【问题标题】:Counts of every 15 min for last 4 days by column wise过去 4 天每 15 分钟按列计数
【发布时间】:2019-03-14 11:06:51
【问题描述】:

我有这个查询,它每 15 分钟输出一次有多少“否”收到。

select trunc(rcv_dt,'hh24') + (trunc(to_char(rcv_dt,'mi')/15)*15)/24/60 as timeline, count(distinct(NO)) as count
from tbl where trunc(rcv_dt) = trunc(SYSDATE -1)
group by  trunc(rcv_dt,'hh24') + (trunc(to_char(rcv_dt,'mi')/15)*15)/24/60
order by trunc(rcv_dt,'hh24') + (trunc(to_char(rcv_dt,'mi')/15)*15)/24/60

输出:

但是,我需要最近几天的类似数据,格式如下。在这方面需要你的帮助。

【问题讨论】:

    标签: sql pivot case


    【解决方案1】:

    我认为这是你想要的:

    select (trunc(to_char(rcv_dt, 'mi')/15)*15)/24/60 as timeline, 
           count(distinct case when trunc(rcv_dt,'hh24') = date '2019-03-13' then NO end) as no_20190313,
           count(distinct case when trunc(rcv_dt,'hh24') = date '2019-03-12' then NO end) as no_20190312,
           count(distinct case when trunc(rcv_dt,'hh24') = date '2019-03-11' then NO end) as no_20190311
    from tbl
    where trunc(rcv_dt) >= date '2019-03-11'
    group by (trunc(to_char(rcv_dt,'mi')/15)*15)/24/60
    order by (trunc(to_char(rcv_dt,'mi')/15)*15)/24/60;
    

    【讨论】:

    • 感谢您的回答。但它只给出 4 行。第一行也没有给出适当的时间。
    • TIMELINE no_20190313 no_20190312 no_20190311 0 108 81 78 0.010416667 14 11 8 0.020833333 6 17 8 0.03125 7 3 11
    猜你喜欢
    • 1970-01-01
    • 2019-12-18
    • 1970-01-01
    • 1970-01-01
    • 2017-10-31
    • 2021-12-28
    • 2017-03-14
    • 2022-09-30
    • 2021-04-05
    相关资源
    最近更新 更多