不使用crosstab实现PostgreSQL的行转列应用
表结构及数据
select logdatetime,sum(login) as login,sum(logo) as logo
from(SELECT date(logdatetime) AS "logdatetime", case logfrom when ‘login‘ then COUNT(id) else 0 end AS "login",
case logfrom when ‘logo‘ then COUNT(id) else 0 end AS "logo"
FROM "log" WHERE date(logdatetime) >= ‘2014-11-04‘ AND date(logdatetime) <= ‘2014-11-05‘ GROUP BY "logdatetime", "logfrom"
) T
GROUP BY "logdatetime"
ORDER BY "logdatetime" ASC
执行结果
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。