1

嗨,我有以下表格结构。

RESE_ID DATE_OF_SERVICE TIME_OF_SERVICE NO_OF_ATT_MALE  NO_OF_ATT_FEMALE
      1     2012-09-18       16:17:52        5                1
      2     2012-09-18       16:19:22        1                2
      3     2012-09-18       16:29:12        2                1
      4     2012-09-18       16:37:22        1                4
      5     2012-09-18       16:49:02        6                5
      6     2012-09-18       17:01:52        3                2
      7     2012-09-18       17:19:52        0                1

我只想要最后 1 小时每 10 分钟 (no_of_att_male) 的总和,例如(16:00 - 17:00)

像输出一样

  RESE_ID DATE_OF_SERVICE  NO_OF_ATT_MALE  NO_OF_ATT_FEMALE    TIME_SLOT
      1     2012-09-18             0                0        16:00 - 16:10   
      2     2012-09-18             6                3        16:11 - 16:20     
      3     2012-09-18             2                1        16:21 - 16:30   
      4     2012-09-18             1                4        16:31 - 16:40    
      5     2012-09-18             6                5        16:41 - 16:50   
      6     2012-09-18             0                0        16:51 - 17:00   

请建议我一个可以在 sqlite 中接受的查询(我在 HTML5 中使用它)

4

1 回答 1

1
SELECT DATE_OF_SERVICE,
       SUM(NO_OF_ATT_MALE),
       SUM(NO_OF_ATT_FEMALE),
       SUBSTR(TIME_OF_SERVICE, 1, 4) || '0 - ' ||
       SUBSTR(TIME_OF_SERVICE, 1, 4) || '9'       AS TIME_SLOT
FROM mytable
GROUP BY 4

这将导致这样的输出,即没有空时隙的记录:

DATE_OF_SERVICE  SUM(NO_OF_ATT_MALE)  SUM(NO_OF_ATT_FEMALE)  TIME_SLOT
---------------  -------------------  ---------------------  -------------
2012-09-18       6                    3                      16:10 - 16:19
2012-09-18       2                    1                      16:20 - 16:29
2012-09-18       1                    4                      16:30 - 16:39
2012-09-18       6                    5                      16:40 - 16:49
2012-09-18       3                    2                      17:00 - 17:09
2012-09-18       0                    1                      17:10 - 17:19
于 2012-09-18T13:05:37.953 回答