LilMoke
LilMoke

Reputation: 3444

SQL Query to show count of same results

I have the following SQL Query:

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

And it produces this:

Score
0
1
2
2
4
5
5

But, what I really want is the number of each of the scores, like this:

Score   Count
0       1
1       1
2       2
4       1
5       2

I want to show how many of each score, One 0, One 1, Two 2's, One 4, and 2 5's.

But I am not sure how to do this query, would someone be able to show me how to achieve this?

Thanks for the help

Upvotes: 2

Views: 107

Answers (3)

Anand
Anand

Reputation: 409

Try this code:

SELECT Score,count(score) as cnt 
FROM ResponseData
WHERE ScoreGUID='baf5dd3e-949c-4255-ad48-fd8f2485399f'
GROUP BY Score

Upvotes: 6

Sai Avinash
Sai Avinash

Reputation: 4753

try the follwoing:

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

Upvotes: 1

ᗩИᎠЯƎᗩ
ᗩИᎠЯƎᗩ

Reputation: 2132

Something like:

SELECT Score, COUNT(Score)
FROM ResponseData
WHERE ScoreGUID='baf5dd3e-949c-4255-ad48-fd8f2485399f'
GROUP BY Score

should work. But I don't understand the meaning of your:

group by Section

Upvotes: 2

Related Questions