我有以下SQL查询:
SELECT Score FROM (
SELECT SUM(Score) AS Score
FROM ResponseData
WHERE ScoreGUID='baf5dd3e-949c-4255-ad48-fd8f2485399f'
GROUP BY Section
) AS Totals
GROUP BY Score
它产生了这个:
Score
0
1
2
2
4
5
5
但是,我真正想要的是每个分数的数量,如下:
Score Count
0 1
1 1
2 2
4 1
5 2
我想显示每个分数中有多少,一个0,一个1,两个2,一个4和2个。
但我不确定如何进行此查询,是否有人能够告诉我如何实现这一目标?
感谢您的帮助
答案 0 :(得分:6)
试试这段代码:
SELECT Score,count(score) as cnt
FROM ResponseData
WHERE ScoreGUID='baf5dd3e-949c-4255-ad48-fd8f2485399f'
GROUP BY Score
答案 1 :(得分:2)
类似的东西:
SELECT Score, COUNT(Score)
FROM ResponseData
WHERE ScoreGUID='baf5dd3e-949c-4255-ad48-fd8f2485399f'
GROUP BY Score
应该有效。但我不明白你的意思:
group by Section
答案 2 :(得分:1)
尝试以下方法:
SELECT Score,count(*) as Count FROM (
SELECT distinct SUM(Score) AS Score
FROM ResponseData
WHERE ScoreGUID='baf5dd3e-949c-4255-ad48-fd8f2485399f'
GROUP BY Section
) AS Totals
GROUP BY Score