小编典典

每小时值的总和

sql

我有一个具有以下结构和示例数据的表:

STORE_ID |  INS_TIME  | TOTAL_AMOUNT
  2         07:46:01    20
  3         19:20:05    100
  4         12:40:21    87
  5         09:05:08    5
  6         11:30:00    12
  6         14:22:07    100

我需要获取每个STORE_ID的每小时总计TOTAL_AMOUNT。我尝试了以下查询,但我不知道它是否正确。

SELECT STORE_ID, SUM(TOTAL_AMOUNT) , HOUR(INS_TIME) as HOUR FROM VENDAS201302 
WHERE MINUTE(INS_TIME) <=59
GROUP BY HOUR,STORE_ID
ORDER BY INS_TIME;

阅读 156

收藏
2021-04-14

共1个答案

小编典典

SELECT STORE_ID,  
       HOUR(INS_TIME) as HOUR_OF_TIME,
       SUM(TOTAL_AMOUNT) as AMOUNT_SUM
FROM VENDAS201302 
GROUP BY STORE_ID, HOUR_OF_TIME
ORDER BY INS_TIME;
2021-04-14