Hey,

I have a problem with a query. I would like to sum the columns grouped by the passportID. the sum is retrieved by a calculation:

However, it does not work properly.
Any suggestions?

Code:
SELECT  c.passportid,(extract(epoch FROM (b.departuredate-b.arrivaldate))::int / (60*60*24)) as "duration", sum(extract(epoch FROM(b.departuredate-b.arrivaldate))::int / (60*60*24)) FROM customer c, booking b, customer_jct_booking cjb WHERE c.passportid = cjb.customers_passportid AND cjb.bookings_bookingid = b.bookingid group by (c.passportid, b.arrivaldate, b.departuredate) ORDER BY (b.departuredate-b.arrivaldate) DESC;