I have an SQL query that currently displays all the people in table HOTEL that booked a hotel between $260 and $350. I’m using ORACLE
SELECT guest.guest_name "GUEST NAME",
Count(guest.guest_no),
guest.guest_no "GUEST NUMBER",
room.r_price "ROOM PRICE"
FROM room,
guest,
booking
WHERE r_price >= 260
AND r_price <= 350
AND guest.guest_no = booking.guest_no
GROUP BY guest.guest_no,
guest.guest_name,
room.room_price
ORDER BY guest.guest_name;
I thought that I could group by just GUEST.GUEST_NAME (so it puts all of the count under the one name rather than doubling up on the guest names).
EDIT: The current results of the query look like this:
GUEST NAME COUNT GUEST_NO R_PRICE
Jenny Freeman 2 G003 260
Jenny Freeman 2 G003 295
Jenny Freeman 2 G003 310
Martin Ferguson 3 G006 260
Martin Ferguson 3 G006 295
Martin Ferguson 3 G006 310
Paul Happy 3 G002 260
Paul Happy 3 G002 295
Paul Happy 3 G002 310
Steve Kirkwood 3 G005 260
Steve Kirkwood 3 G005 295
Steve Kirkwood 3 G005 310
Tina Duncan 2 G001 260
Tina Duncan 2 G001 295
Tina Duncan 2 G001 310
Vanessa Horton 1 G007 260
Vanessa Horton 1 G007 295
Vanessa Horton 1 G007 310
But I’m expecting something like this:
GUEST NAME COUNT GUEST_NO R_PRICE
Jenny Freeman 6 G003 260
Martin Ferguson 9 G006 310
Paul Happy 9 G002 310
Steve Kirkwood 9 G005 260
Tina Duncan 6 G001 310
Vanessa Horton 3 G007 260
Well, I think you just have to change in group by statement rest looks OK to me. Just don’t include Room price in Group By statement, i think that is creating problem for you if i am getting your question right…
and