我在postgres中有一张表,该表由纪元时间戳索引..现在我想查询该表以获取特定日期之间没有事件的计数...我已经在postgres中对其进行了查询,但我不确定我如何在休眠状态下实现此目标而无需在休眠状态下编写本机postgres查询...。
我的表结构是
event
-----------------
id, created, updated, event_type, source_machine timestamp
1 07.05.2011 event1 machine1 938970822
2 07.05.2011 event2 machine2 1332949476
3 07.05.2011 NullPointerException machine2 648034359
4 06.05.2011 event2 machine2 1173340611
5 06.05.2011 event1 machine1 1391797768
6 05.05.2011 event2 machine1 849970844
7 04.05.2011 event1 machine2
*Currently, table has 10k rows.
仅供参考:我不能为此使用CREATED列,我只能使用时间戳...到目前为止,我在postgres中编写的查询是...
select event_type,to_char(to_timestamp(timestamp),'YYYY-MM-DD') AS date_range,count(*) from event where to_char(to_timestamp(timestamp),'YYYY-MM-DD') between to_char(to_timestamp(549788400),'YYYY-MM-DD') and to_char(to_timestamp(1403247600),'YYYY-MM-DD') and event.machine = 'machine1' group by event_type,to_char(to_timestamp(timestamp),'YYYY-MM-DD');
如果我不使用它,例如,我必须使用“ to_char”。“ 2010-03-31 23:59:59”。边界条件有潜在危险:如果系统在23:59:59到00:00:00之间发生交易,我会错过它。任何帮助,将不胜感激。
我做了一个支持hibernate的查询。如果有人正在寻找类似问题的答案,这是我的解决方案。以上在HQL中的查询。
SELECT new map(E.event_type as name,to_char(to_timestamp(E.timestamp),'MM-DD-YYYY') AS key,count(*) as value) from Event E WHERE E.timestamp BETWEEN " + startTime + " and " + endTime + " AND E.platform = '"+platform+"' AND E.event_type = '"+eventName+"' GROUP BY E.event_type,to_char(to_timestamp(E.timestamp),'MM-DD-YYYY') ORDER BY to_char(to_timestamp(E.timestamp),'MM-DD-YYYY')";
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句