OK I'm having trouble with this problem on my homework. I got the rest OK, I don't know why this problem is stumping me.
List the number of rooms in each hotel.
Tables:
HOTEL: (hotelNo, hotelName, city)
ROOM: (roomNo, hotelNo, type, price)
BOOKING: (hotelNo, guestNo, dateFrom, DateTo, roomNo)
GUEST: (guestNo, guestName, guestAddress)
here's what I have tried, but it's not working.....
SELECT hotelNo, COUNT (roomNo) AS roomcount
FROM room
WHERE (SELECT DISTINCT hotelNo FROM hotel)
ORDER BY hotelNo
and
SELECT COUNT (roomNo)
FROM room
WHERE h.hotelNo = r.hotelNo
Order By hotelNo
Any clues or advice and any help will be appreciated.
8 1603
Hi teddarr
what is in table room, column roomNo ? is there one record for every room in every hotel or is it one row per hotel with the number of rooms in it ?
Purple
table room contains one row for every room in every hotel. The table also contains hotelNo which gives the distinct hotel.
Is there any cascade dependency with other tables.
Can you please post what exactly is the error you are getting.
Hi teddar,
I think this should do what you need... - SELECT hotel.hotelNo, COUNT(room.roomNo) AS num_rooms
-
FROM hotel INNER JOIN
-
room ON hotel.hotelNo = rooom.hotelNo
-
GROUP BY hotel.hotelNo, room.roomNo
I think you need to do some reading around joins and group by..
Regards Purple
Purple,
Your recommendation on reading is right on. That is exactly where my mental hang up is.
I tried your statements and even added a line that reads WHERE hotel.hotelNo = room.hotelNo
The result I get is about 5 entries with the number 1 next to each hotelNo instead of a count.
example:
hotelNo num_rooms
1 1
1 1
1 1
1 1
1 1
1 1
1 1
2 1
2 1
2 1
2 1
3 1
3 1
3 1
3 1
3 1
This gets me closer but I still don't know what to do from here.
Hi,
is hotel.hotelNo unique ?
for info - WHERE hotel.hotelNo = room.hotelNo is not required - the join is doing this for you in this : hotel.hotelNo = rooom.hotelNo
do me a :
and
and post some of the output into the thread plse
Purple
I got it!
Thanks Purple. With yours and the guys at work giving advice, I now have a solution:
SELECT hotel.hotelNo, COUNT(room.roomNo) AS numRooms
FROM hotel INNER JOIN room ON hotel.hotelNo = room.hotelNo
GROUP BY hotel.hotelNo;
You and the guys at work both pointed out that the WHERE clause was redundant. Thanks for the heads up.
Hi,
This is May be Help For u
SELECT H.HotelNo as HotelCode,Count(R.RoomNo),H.CITY as NoOfRooms
FROM Hotel H INNER JOIN ROOM R ON
H.HotelNo=R.HotelNo
Group By H.HotelNo,H.CITY
Bye
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Kishor |
last post by:
Hi Friends
Please help me to write a C program to find the 5th (fifth) root of a given number.
Ex:(1) Input : 32
Output : 5th root of 32 is 2
Ex:(1) Input : 243
Output : 5th root of 243 is...
|
by: suzee_q00 |
last post by:
I will admit that lots of times the obvious eludes me and this is most likely one of those times but if anyone has any ideas on what I can do to make this code work, I would greatly appreciate it....
|
by: stonemcstone |
last post by:
I've been programming in C for years, and never experienced troubles
until I started using the new RealC-32, a freeware C compiler from the
same company that makes RealPlayer and Quicktime. That's...
|
by: redpayne |
last post by:
Ok-I am doing homework out of a book and the instructions are to display an interface with 5 option buttons in a frame. When clicked, each button changes the background color of the frame. It...
|
by: Rico |
last post by:
Hello,
I have an MDE application where I use a bound object frame to display an
image. This frame is updatable and bested on the contents of an OLE field.
My problem is, some images display as...
|
by: MISSMIS |
last post by:
hello friends,
I cannot get my access to open on my computer. It just acts as if it is installing and configuring and the screen looks like it refreshes but access never opens up. Has anyone ever...
|
by: Ganon11 |
last post by:
Hey guys,
OK, taking care of this beforehand; I AM a student in a university. This IS part of my homework, and (as a moderator), I'm doing my best to follow the posting guidelines I work so hard...
|
by: garyrowell |
last post by:
I have been at this programme for hours trying to work out what is wrong. Any help would be very much appricated. Here is the breif I received.
The program
This week you are going to write three...
|
by: Three Headed Monkey |
last post by:
write a program in "C" language that computes 9^(8^(7^(6^(5^(4^(3^(2^1)))))))
I tried
#include <stdio.h>
int pow(int n)
{
int i,power;
power=n;
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |