If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Hey all, need some Help.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-27-11, 06:10
coccoster coccoster is offline
Registered User
 
Join Date: Apr 2009
Posts: 9
Hey all, need some Help.

Hey guys.

Doing some SQL coding and have come up with some trouble as to how i solve this query.

Show how many bookings have been made for each room that has a spa bath

I have two tables:

Booking
-Booking_no
-Guest_no
-Room_no
-Date_In
-Date_Out

Room
-Room_no
-Floor_no
-Spa_Bath
-Num_Beds
-Price
-Linked_Room_No

So far i have:

SELECT COUNT(booking_no) , room_no
FROM booking, room
WHERE spa_bath = 'Y'
group by booking.room_no

but doesnt seem right to me LOL.

Anyone able to help me solve this for me?
Reply With Quote
  #2 (permalink)  
Old 04-27-11, 06:42
dav1mo dav1mo is offline
Registered User
 
Join Date: Dec 2007
Location: Richmond, VA
Posts: 782
what are you joining the 2 tables on?
Dave
Reply With Quote
  #3 (permalink)  
Old 04-27-11, 21:46
coccoster coccoster is offline
Registered User
 
Join Date: Apr 2009
Posts: 9
not to sure, im guessing id have to use room_no?
Reply With Quote
  #4 (permalink)  
Old 04-28-11, 02:21
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,250
As Dav1mo suggests what you need is a mechanism to join, or realte the two tables. that means a single piece of information that is common to both tables...

you could use an additional element in the where clause
Code:
....
WHERE spa_bath = 'Y'
AND Booking.RoomNo = Room.RoomNo
however that style of declaration is depracated and more modern usage would be to define a JOIN
Code:
SELECT COUNT(booking_no) , booking.room_no
FROM booking
JOIN Room on Room.RoomNo = Booking.RoomNo
WHERE spa_bath = 'Y'
group by booking.room_no
MySQL :: MySQL 5.5 Reference Manual :: 12.2.9.1 JOIN Syntax

however select count (booking_no) doesn't make sense as Im guessign you can only ever have one booking
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On