我有一个查询来查找每天登录多次的给定用户的登录次数:
SELECT login_id, count(*) FROM login_test GROUP BY login_id HAVING count(*) > 1;
如何获得所有多次登录的sum
?我尝试过类似的事情:
SELECT SUM(SELECT count(*) FROM login_test GROUP BY login_id HAVING count(*) > 1);
没有运气。
答案 0 :(得分:0)
使用派生表:
SELECT sum(count)
FROM (
SELECT login_id, count(*)
FROM login_test
GROUP BY login_id
HAVING count(*) > 1
) s;
答案 1 :(得分:0)
Select sum(t.cnt) as agg_count
from
(Select count(*) as cnt
from table1
Group by id having count(*) > 1
) t