日期:2014-05-17 浏览次数:21310 次
SELECT '00:00-02:00' AS h, SUM(nFlow) AS s FROM flowdata WHERE msgtime BETWEEN to_date('2011-12-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS') AND to_date('2011-12-01 02:00:00', 'YYYY-MM-DD HH24:MI:SS') UNION ALL SELECT '02:00-04:00' AS h, SUM(nFlow) AS s FROM flowdata WHERE msgtime BETWEEN to_date('2011-12-01 02:00:00', 'YYYY-MM-DD HH24:MI:SS') AND to_date('2011-12-01 04:00:00', 'YYYY-MM-DD HH24:MI:SS') UNION ALL SELECT '04:00-06:00' AS h, SUM(nFlow) AS s FROM flowdata WHERE msgtime BETWEEN to_date('2011-12-01 04:00:00', 'YYYY-MM-DD HH24:MI:SS') AND to_date('2011-12-01 06:00:00', 'YYYY-MM-DD HH24:MI:SS') UNION ALL SELECT '06:00-08:00' AS h, SUM(nFlow) AS s FROM flowdata WHERE msgtime BETWEEN to_date('2011-12-01 06:00:00', 'YYYY-MM-DD HH24:MI:SS') AND to_date('2011-12-01 08:00:00', 'YYYY-MM-DD HH24:MI:SS') UNION ALL SELECT '08:00-10:00' AS h, SUM(nFlow) AS s FROM flowdata WHERE msgtime BETWEEN to_date('2011-12-01 08:00:00', 'YYYY-MM-DD HH24:MI:SS') AND to_date('2011-12-01 10:00:00', 'YYYY-MM-DD HH24:MI:SS') UNION ALL SELECT '10:00-12:00' AS h, SUM(nFlow) AS s FROM flowdata WHERE msgtime BETWEEN to_date('2011-12-01 10:00:00', 'YYYY-MM-DD HH24:MI:SS') AND to_date('2011-12-01 12:00:00', 'YYYY-MM-DD HH24:MI:SS')
------解决方案--------------------
楼主可以将5楼的内容写到存储过程里呀,通过循环去组装这些语句呀!
------解决方案--------------------
如果是查询一个月显示每天数量到是有简单方法 查小时应该只有查询每个时段拼接了