mercredi 27 janvier 2016

Sum MSSQL Count field from Grouped queryH

I am trying to write a query that takes all content from my db that has been rated higher than 3 stars and returns the top four modules based on star average and highest numbers of ratings. This part works great. But in order for me to put this into a graph, I need the percentage. So, I need the summary of the count(id_module) field. I have read through a lot of posts and tried to implement a number of solutions but have not been successful - can anyone shed any light for me? I have pasted my query below and the results it brings back - this part works fine... I just need to know how to get the sum of the id module fields - which in this case would be 23... thanks for any help offered!

SELECT TOP 4 AVG(rating) AS ratingstars, COUNT(id_module) AS countmodules,  FROM [db]
WHERE 
(rating > 3)
 GROUP BY id_module ORDER BY ratingstars DESC, countmodules DESC

ratingstars = 5, 5, 5, 5 countstar = 18, 2, 2, 1 (need the sum of these)

Aucun commentaire:

Enregistrer un commentaire