0

我有这张桌子:

TABLE T (
id int, 
month int,
interval hours
);

我想按 id 和月份分组,并添加小时数。例如:

id  month  hours
-------------------
 1  1      08:00:00  
 1  1      09:00:00 
 1  2      10:00:00 
 1  2      11:00:00 

我想:

1 1  17:00:00
1 2  21:00:00

我试过这个:

SELECT * FROM T 
GROUP BY T.id , T.month
HAVING SUM( SELECT EXTRACT ( epoch FROM T.hours ) / 3600 );

但它不起作用,我无法修复它。

4

1 回答 1

0
SELECT
  id,
  month,
  sum(extract ('epoch' from hours)/3600)
FROM
  hours
GROUP BY
  id,
  month

SQL小提琴

于 2013-11-06T04:22:26.693 回答