|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
Problem with query - sum()
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? 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; |
|
#2
|
|||
|
|||
|
Quote:
Is this query run?, i think there should be group by clause |
|
#3
|
|||||
|
|||||
|
It does not work properly means nothing, describe the exact problem or error and show your case with a meaningful example.
Also formatting your queries makes them more readable ... sql Code:
__________________
My blog about OpenSource Databases PDF tutorials about OSS databases, DBMonster ... Please contribute to Open Source Development, fill bug reports!!! Developer Shed eSupport Commented my.ini/my.cnf (PLEASE ADD YOUR OWN CONFIG TRICK) An introduction to database normalization Natural or Surrogate key Custom ordering for your results Correlated and uncorrelated subqueries Don't turn your outer joins into inner joins |
![]() |
| Viewing: Dev Shed Forums > Databases > PostgreSQL Help > Problem with query - sum() |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|