在我的SQl服务器Sp.
`SELECT rating as [Rating],count(id) as [RatingCount]
FROM MMBPollResults
where mmb_id = @MMbid
GROUP BY rating
This SP returns the rating for each user.
i:e rating ratingcount
` 1 2
2 1
5 4所以这意味着
2users have rated the transaction with 1star
1 user has rated the transaction with 2stars
4 users have rated the transaction with 5stars这就是我需要的输出
rating ratingcount
` 1 2
2 1
3 0
4 0
5 4对不起,如果这是一个愚蠢的问题,谢谢Sun
发布于 2011-08-02 03:24:00
你需要一个从1到5的表格。这可以是一个数字表格或其他评级表格。
在这里,我使用一个简单的UNION来创建一个包含1到5的表
SELECT
List.Rating,
count(MMB.*) as [RatingCount]
FROM
(
SELECT 1 AS Rating
UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5
) List
LEFT JOIN
MMBPollResults MMB ON List.Rating = MMB.Rating AND MMB.mmb_id = @MMbid
GROUP BY
List.Rating
ORDER BY
List.Rating;https://stackoverflow.com/questions/6903254
复制相似问题