Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Pivot
Hi
I try to make two fields one for sales2005 and one for sales2004. I tried to
join the table with itself but the result for 2005 is not correct. The SQL
statement I use looks like this:
SELECT SUM (sr.room_nights) SALES2004, SUM(sr2.room_nights) SALES2005
FROM stay_records sr, stay_records sr2 WHERE
sr.guest_name_id = sr2.guest_name_id AND sr.actual_departure_date BETWEEN '01-jan-2004' AND
'31-dec-2004'
AND sr2.actual_departure_date BETWEEN '01-jan-2005' AND
GROUP BY
sr.guest_name_id
The result for 2004 is correct but the one for 2005 is the sum of sr_room_nights in all rows found multiplied by two. How do I do to get it right
Thanks
/Diedrik Received on Sun Mar 20 2005 - 13:57:40 CST