我已编写查询以获取特定日期的数据,但需要查询以每小时和每天的方式获取数据
我的查询
SELECT
TRAN_USERTRANSACTIONS.APPLICATIONNUMBER
FROM
TRAN_USERTRANSACTION
WHERE TRAN_USERTRANSACTIONS.CREATEDAT
LIKE '%19-09-19%'
GROUP BY
TRAN_USERGTRANSACTION.APPLICATIONNUMBER;
CREATEDAT是Timestampin,其格式如下:DD-MM-YY hh.mm.ss.ssss AM / PM
答案 0 :(得分:0)
按小时(希望有帮助):
Select TRAN_USERTRANSACTIONS.APPLICATIONNUMBER
, TO_CHAR(TRAN_USERTRANSACTIONS.CREATEDAT ,'HH AM')
from TRAN_USERTRANSACTION
WHERE TRAN_USERTRANSACTIONS.CREATEDAT LIKE '%19-09-19%'
group by TRAN_USERTRANSACTIONS.APPLICATIONNUMBER
, TO_CHAR(TRAN_USERTRANSACTIONS.CREATEDAT ,'HH AM')
order by TO_CHAR(dat_azu,'HH AM') asc;
答案 1 :(得分:0)
我假设您想要按小时而不是按应用程序进行汇总。如果是这样,则小时应在GROUP BY
中:
SELECT TO_CHAR(t.CREATEDAT, 'YYYY-MM-DD HH24') as dh,
COUNT(*)
FROM TRAN_USERTRANSACTION t
WHERE t.CREATEDAT >= DATE '2019-09-19' AND
t.CREATEDAT < DATE '2019-09-20'
GROUP BY TO_CHAR(t.CREATEDAT, 'YYYY-MM-DD HH24')
ORDER BY dh;