表结构及数据
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
执行结果
总结
以上是内存溢出为你收集整理的不使用crosstab实现PostgreSQL的行转列应用全部内容,希望文章能够帮你解决不使用crosstab实现PostgreSQL的行转列应用所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)