Question

I've got this table:

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

and I want to group by id and month, and add the hours. For example:

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

I want:

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

I tried this:

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

but it doens't work and I can't fix it.

Était-ce utile?

La solution

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

SQL Fiddle

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top