软件下载吧文章资讯

分类分类

PostgreSQL 数据库基础 动态统计某一列的某一值出现的次数SQL

2024-02-07 12:09作者:下载吧

实例解析:

select to_char(log.date, ‘yyyy-MM-dd HH24’) as hour,
log.exten, sum(case log.grade when ‘1’ then 1 else 0 end) as “1”,
sum(case log.grade when ‘2’ then 1 else 0 end) as “2”,
sum(case log.grade when ‘3’ then 1 else 0 end) as “3”,
sum(case log.grade when ‘4’ then 1 else 0 end) as “4”,
sum(case log.grade when ‘5’ then 1 else 0 end) as “5”,
log.direction from iface_satisfaction_investigation as log
where log.date >= ‘2017-08-03 00:00:00’ and log.date < ‘2017-08-04 00:00:00’
group by hour,log.exten,log.direction order by hour,log.exten,log.direction asc

展开全部

相关文章

说两句网友评论
    我要跟贴
    取消