当日期和时间是单独的列时,SQL查询按小时求和

时间:2017-06-24 19:23:01

标签: mysql select

我有一个表,其中A列中的日期,B列中的时间和C列中的值。我希望计算出给定商店每天的每小时总价值。也就是说,使用单个SQL查询,我希望获得storeid,日期以及当天每小时为该商店在该小时内生成的值。

我希望你能提供帮助和谢谢。

1 个答案:

答案 0 :(得分:-1)

这似乎完成了这项工作:

SELECT eventdate, HOUR(eventfromtime), SUM(direction1) as direction1
  FROM totalentrance
  WHERE eventdate >= '2017-05-11'
  AND eventdate < '2017-05-13'
and storeid=8185
  GROUP BY eventdate, HOUR(eventfromtime)
  ORDER BY eventdate, eventfromtime;

产地:

2017-05-11  0   0
2017-05-11  1   0
2017-05-11  2   0
2017-05-11  3   0
2017-05-11  4   0
2017-05-11  5   0
2017-05-11  6   0
2017-05-11  7   0
2017-05-11  8   0
2017-05-11  9   1
2017-05-11  10  27
2017-05-11  11  22
2017-05-11  12  20
2017-05-11  13  24
2017-05-11  14  20
2017-05-11  15  26
2017-05-11  16  16
2017-05-11  17  24
2017-05-11  18  10
2017-05-11  19  2
2017-05-11  20  0
2017-05-11  21  0
2017-05-11  22  0
2017-05-11  23  0
2017-05-12  0   0
2017-05-12  1   0
2017-05-12  2   0
2017-05-12  3   0
2017-05-12  4   0
2017-05-12  5   0
2017-05-12  6   0
2017-05-12  7   0
2017-05-12  8   0
2017-05-12  9   8
2017-05-12  10  11
2017-05-12  11  6
2017-05-12  12  18
2017-05-12  13  20
2017-05-12  14  17
2017-05-12  15  21
2017-05-12  16  9
2017-05-12  17  15
2017-05-12  18  1
2017-05-12  19  0
2017-05-12  20  0
2017-05-12  21  0
2017-05-12  22  0
2017-05-12  23  0