选择查询以显示时间戳(HH:MM:SS)colomn与组HH(ORACLE QUERY)

时间:2018-03-02 22:22:50

标签: sql oracle

我正在尝试在oracle中创建select查询以从my_table获取以下结果

表格内容timestamp_coloumn和count coloumn,timestamp_colomn中的记录将按分钟基数插入。

尝试查询: - 像这样

coefs = np.array([-10.07375729,  15.61272995,   2.45089647,  33.58025209])
xx = np.linspace(0, 1, 10)
yy = np.linspace(0, 1, 10)
YY, XX = np.meshgrid(yy, xx)
z = (-coefs[1] * XX- coefs[2] * YY - coefs[0]) * 1. /coefs[3]
plane = SurfacePlot(x=xx, y=yy, z=z, color=(0.3, 0.3, 1, 1), parent=view.scene)

错误: -

 select to_char(timestamp_coloumn ,'HH24:MI:SS') as TS , count as count 
 from my_table 
 group by to_char(timestamp_coloumn ,'HH24');

如果,我匹配select和group by语句,如下所示,但是,我无法达到我预期的结果(我不知道这样查询是否正确)

ORA-00979: not a GROUP BY expression

预期结果(每小时时间戳和计数被分组并对该小时内存在的所有记录求和): -

select to_char(timestamp_coloumn ,'HH24:MI:SS') as TS , count as count 
from my_table 
group by to_char(timestamp_coloumn ,'HH24:MI:SS');

请帮我解决这个问题

1 个答案:

答案 0 :(得分:1)

您可以使用MIN()

 select min(to_char(timestamp_coloumn ,'HH24:MI:SS')) as TS, count(*) 
 from my_table 
 group by to_char(timestamp_coloumn ,'HH24');

或者使两个表达式匹配:

 select to_char(timestamp_coloumn ,'HH24') as TS, count(*) 
 from my_table 
 group by to_char(timestamp_coloumn ,'HH24');