我使用以下查询来获得按小时计算的数据:
select to_char(trunc(time, 'HH'), 'DD/MM/YY HH24') as "date",
count(event), count(distinct id) from source
where time >= date '2021-01-01'
group by trunc(time,'HH')
order by trunc(time,'HH');
我现在想做的是一样的,但以分钟为基础。我该怎么做?
对我来说,你本可以完全避免trunc
,因为你无论如何都使用TO_CHAR
:
select to_char(time, 'dd/mm/yy hh24') ...
如果你想包括分钟数,没问题:
select to_char(time, 'dd/mm/yy hh24:mi') as "date",
count(event), count(distinct id)
from source
where ...
group by to_char(time, 'dd/mm/yy hh24:mi')
请注意,按字符串排序可能不会产生所需的结果。也许,如果您将日期格式更改为例如'yyyymmdd hh24:mi'