473,383 Members | 2,005 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Trouble with homework

143 100+
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.
Jun 24 '07 #1
8 1603
Purple
404 Expert 256MB
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
Jun 24 '07 #2
teddarr
143 100+
table room contains one row for every room in every hotel. The table also contains hotelNo which gives the distinct hotel.
Jun 24 '07 #3
debasisdas
8,127 Expert 4TB
Is there any cascade dependency with other tables.

Can you please post what exactly is the error you are getting.
Jun 25 '07 #4
Purple
404 Expert 256MB
Hi teddar,

I think this should do what you need...

Expand|Select|Wrap|Line Numbers
  1. SELECT    hotel.hotelNo, COUNT(room.roomNo) AS num_rooms
  2. FROM         hotel INNER JOIN
  3.                       room ON hotel.hotelNo = rooom.hotelNo
  4. GROUP BY hotel.hotelNo, room.roomNo
I think you need to do some reading around joins and group by..

Regards Purple
Jun 25 '07 #5
teddarr
143 100+
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.
Jun 25 '07 #6
Purple
404 Expert 256MB
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 :

Expand|Select|Wrap|Line Numbers
  1. select * from hotel
and

Expand|Select|Wrap|Line Numbers
  1. select * from room
and post some of the output into the thread plse

Purple
Jun 25 '07 #7
teddarr
143 100+
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.
Jun 26 '07 #8
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
Jun 26 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

13
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...
9
suzee_q00
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....
27
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...
1
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...
4
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...
2
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...
17
Ganon11
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...
8
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...
24
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;
0
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...
0
isladogs
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...
0
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...
0
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,...
0
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...
0
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...
0
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
1
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...
0
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.