【发布时间】:2017-01-05 16:24:58
【问题描述】:
我需要通过 acc_id 和 SUM(6 - total) 选择 tableA、count(id) 组。
TableA
ID | acc_id | user_id
1 | 2 | 20
2 | 2 | 21
3 | 3 | 22
4 | 3 | 10
预期结果:
total: 8
我试过了:
select 6-count(id) as total
from tableA
group by acc_id
having total < 6 AND total <> 0
我的输出:
total: 4, total: 4
我只需要最后总结一下。我该怎么做?
【问题讨论】:
-
checkout
rollupmysql 中的函数以及group by -
什么是
6-count(id) -
@RiggsFolly:我认为他计算了 id 的数量,然后计算出 6 减去该数字。所以
6 - COUNT(id) -
@WillemVanOnsem 哦,是的... DUH 傻我
-
是的,我需要分这个号码