gpt4 book ai didi

sql - Oracle SQL 组按 10 分钟时间间隔的行计数

转载 作者:行者123 更新时间:2023-12-02 13:13:19 24 4
gpt4 key购买 nike

我在 oracle 中有一个表,其中包含如下数据

created_date       details  01-Jan-16 04:45    abcd  01-Jan-16 04:47    efgh  01-Jan-16 04:53    ijkl  01-Jan-16 04:54    mnop  01-Jan-16 04:58    qrst  

...等等

我希望能够每 10 分钟计算一次表中的行数例如

Time    count04:40       204:50       3

创建日期=时间戳,详细信息 = varchar

我该怎么做?

谢谢

最佳答案

您可以使用 TO_CHAR 和 SUBSTR 构建时间字符串:

select
substr(to_char(created_date, 'hh24:mi'), 1, 4) || '0' as created,
count(*)
from mytable
group by substr(to_char(created_date, 'hh24:mi'), 1, 4) || '0'
order by substr(to_char(created_date, 'hh24:mi'), 1, 4) || '0';

或者使用子查询(派生表),以便只需编写一次日期表达式:

select created, count(*)
from
(
select substr(to_char(created_date, 'hh24:mi'), 1, 4) || '0' as created
from mytable
)
group by created
order by created;

关于sql - Oracle SQL 组按 10 分钟时间间隔的行计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34723120/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com