我有这张桌子:
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 );
但它没有用,我无法修复它。
答案 0 :(得分:0)
SELECT
id,
month,
sum(extract ('epoch' from hours)/3600)
FROM
hours
GROUP BY
id,
month