mysql:group by不起作用

时间:2017-06-12 12:27:01

标签: mysql

这是我的查询

SELECT r.stars
FROM ratingstar r
INNER JOIN proposals p ON p.jobid = r.jobid
INNER JOIN us_signup u ON u.id = p.userid
WHERE r.type =  'user'
AND u.id =  '54'
LIMIT 0 , 30

返回

分= [2,3,4]

但我希望它返回count = 3和stars = 9

我试过

SELECT count(*), count(r.stars)
FROM ratingstar r
INNER JOIN proposals p ON p.jobid = r.jobid
INNER JOIN us_signup u ON u.id = p.userid
WHERE r.type =  'user'
AND u.id =  '54'
GROUP BY r.stars
LIMIT 0 , 30

但没有给我预期的结果

1 个答案:

答案 0 :(得分:1)

如果您只想要两个值,则可以使用select replace('Hello [GuestName] welcome to my page', '[GuestName]', 'GuestName') COUNT(不使用SUM),例如:

GROUP BY

如果您想要计算不同的值,可以使用SELECT COUNT(r.stars) AS 'count', SUM(r.stars) AS 'stars' FROM ratingstar r INNER JOIN proposals p ON p.jobid = r.jobid INNER JOIN us_signup u ON u.id = p.userid WHERE r.type = 'user' AND u.id = '54';