i have one table in my database say mytable, which contents request coming from other source. There is one column in this table as Time, which stores date and time(e.g. 2010/07/10 01:21:43) when request was received. Now i want to fetch the data from this table on hourly basis for each day. Means i want count of requests database receive in each hours of a day. e.g.for 1 o'clock to 2 o'clock say count is 50 ..like this.. I will run this query at the end of day. So i will get requests received in a day group by each hour.

我的数据库中有一个表说mytable,其中的内容请求来自其他来源。此表中有一列为Time,它在收到请求时存储日期和时间(例如2010/07/10 01:21:43)。现在我想每小时从这个表中获取数据。意味着我希望数据库在一天中的每个小时内收到数量。例如,从1点钟到2点钟,计数是50 ..像这样..我将在一天结束时运行此查询。所以我会按小时收到一天中收到的请求。

Can anybody help me in this.

任何人都可以帮助我。

I want query which will take less time to fetch the data as my database size is huge.

我想要查询,因为我的数据库大小很大,所以需要更少的时间来获取数据。

Any othre way than OMG Ponies answer.

任何比OMG小马更回答的方式。

2 个解决方案

#1


7

Use the TO_CHAR function to format the DATETIME column, so you can GROUP BY it for aggregate functions:

使用TO_CHAR函数格式化DATETIME列,因此您可以将GROUP BY用于聚合函数:

  SELECT TO_CHAR(t.time, 'YYYY-MM-DD HH24') AS hourly,
         COUNT(*) AS numPerHour
    FROM YOUR_TABLE t
GROUP BY TO_CHAR(t.time, 'YYYY-MM-DD HH24')

更多相关文章

  1. 使用不同的条件,在同一个表的一个SQL查询中使用多个聚合函数
  2. PHP OOP - 调用非obj上的成员函数[重复]
  3. sqlserver的常用函数
  4. SQLSERVER2005调试存储过程跟函数
  5. SQL Server中的TextPtr函数
  6. MySQL字符串相加函数如何运行?似曾相识还是记一笔吧
  7. mysql自定义排序规则函数——field()
  8. oracle基础知识总结 part 3 : 三范式,PLSQL,存储过程,函数,触发器
  9. sql 内置函数 获取表的 列名

随机推荐

  1. 从无到有,支付路由系统升级打怪之路|原创
  2. CTF之Five86-1靶机***实战
  3. Android(安卓)S5PV210 camera驱动(tw9912)
  4. Vue 第一次 commit 原来是这个样子
  5. 人生新篇章
  6. 使用 apiDoc 为你的Node.js API 自动生成
  7. 一步步从头搭建 Vue 开发环境
  8. 8 个你不知道的 DOM 功能[每日前端夜话0x
  9. 从输入 URL 到展现涉及哪些缓存环节(非常
  10. 一笔订单,但是误付了两笔钱!这种重复付款异