[英]aggregate count in postgres
I have a query to find the number of logins by a given user who has logged in more than once per day: 我有一个查询来查找每天多次登录的给定用户的登录次数:
SELECT login_id, count(*) FROM login_test GROUP BY login_id HAVING count(*) > 1;
How can I get the sum
of all the multiple logons? 如何获得所有多个登录的
sum
? I've tried something like: 我已经尝试过类似的东西:
SELECT SUM(SELECT count(*) FROM login_test GROUP BY login_id HAVING count(*) > 1);
with no luck. 没有运气。
Use a derived table: 使用派生表:
SELECT sum(count)
FROM (
SELECT login_id, count(*)
FROM login_test
GROUP BY login_id
HAVING count(*) > 1
) s;
Select sum(t.cnt) as agg_count
from
(Select count(*) as cnt
from table1
Group by id having count(*) > 1
) t
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.