sql怎么查询分组后所有组一共有多少行数.

count(),只能统计每组有多少行,我现在想统计每组一共有多少行该怎么做?

SELECT COUNT(1) count,ac.chanceId,act.quantity,act.fullScale
FROM actgamechance ac 
LEFT JOIN actredpacketrain act ON ac.rainId = act.rainId 
WHERE ac.chanceState = 0 AND (NOW()<=ac.expireTime AND NOW()>=ac.effectiveTtime) 
AND ac.userInfoId = '001ecc591eeb4ee180a35b29da89b395'
GROUP BY ac.sources
ORDER BY act.rainLevel DESC
FOR UPDATE

查询为

2 1 50 50
2 3 50 50

变为

2 1 50 50 4(所有的count相加)
2 3 50 50 4(所有的count相加)

怎么实现?

阅读 7k
1 个回答

尝试使用
http://segmentfault.com/q/1010000004152762

select
c, chanceid, quantity, fullscale, 
@total := @total + c as s
from (
SELECT COUNT(1) count,ac.chanceId,act.quantity,act.fullScale
FROM actgamechance ac 
LEFT JOIN actredpacketrain act ON ac.rainId = act.rainId 
WHERE ac.chanceState = 0 AND (NOW()<=ac.expireTime AND NOW()>=ac.effectiveTtime) 
AND ac.userInfoId = '001ecc591eeb4ee180a35b29da89b395'
GROUP BY ac.sources
) as j, (select @total := 0) as t
ORDER BY act.rainLevel DESC
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题