Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Database Server Software > Oracle > Noob Join/Query help

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-11-07, 23:43
Guldan Guldan is offline
Registered User
 
Join Date: Oct 2007
Posts: 3
Noob Join/Query help

Hi guys, im new to the forum. currently im taking a computer information tech diploma course and am in entry level database.

Ive struggled my way through this assignment.. I don't want free answers but im done everything except one view and a bonus question. Can someone help me ? not just the answer but an explination.. I'm finding Joins and Subqueries very hard to wrap my head around.. anyways here are the two questions:



6) To help the front desk clerk do guest billings, [a - 6 marks, b - 2 marks]
(a) create a view to calculate the account (i.e. running total todate) for each guest at the Grosvenor Hotel; the view should include the room number, guest name, check-in date, check-out date (today), room rate, the duration in days, and the calculated total dollars
(b) write a SELECT query to demonstrate your view (Use 2007-10-09 as current date if needed).
Optional Bonus Question: up to 10 marks but restricted by allowable maximum for course:
7) Find the most commonly booked room type(s) for each hotel in London? For each hotel, list the hotel number, room type and the number of bookings.

Here are the tables, let me know if you need the data inserted.

CREATE TABLE Hotel
(hotelNo NUMBER(4) NOT NULL
,hotelName VARCHAR2(16) NOT NULL
,hotelAddress VARCHAR2(40) NOT NULL
,PRIMARY KEY (hotelNo)
);

CREATE TABLE Room
(hotelNo NUMBER(4) NOT NULL
,roomNo NUMBER(4) NOT NULL
,type VARCHAR2(8) NOT NULL
,price NUMBER(6,2) NOT NULL
,PRIMARY KEY (hotelNo, roomNo)
);

CREATE TABLE Guest
(guestNo NUMBER(4) NOT NULL
,guestName VARCHAR2(15) NOT NULL
,guestAddress VARCHAR2(40) NOT NULL
,PRIMARY KEY (guestNo)
);

CREATE TABLE Booking
(hotelNo NUMBER(4) NOT NULL
,guestNo NUMBER(4) NOT NULL
,dateFrom DATE NOT NULL
,dateTo DATE
,roomNo NUMBER(4) NOT NULL
,PRIMARY KEY (hotelNo, guestNo, dateFrom)
);

thank you, and go easy :}
Reply With Quote
  #2 (permalink)  
Old 10-12-07, 02:13
Littlefoot Littlefoot is offline
Lost Boy
 
Join Date: Jan 2004
Location: Croatia, Europe
Posts: 2,717
Basically, CREATE TABLE and INSERT INTO statements are always welcome - those will help other Forum members to create a testing environment.

However, it is not our job to do your homework. You won't benefit from a complete solution as you won't learn anything from it. The right way to do this task is: YOU do the coding. Run it, correct syntax errors and come back to ask a question about the SPECIFIC problem you have (for example, "query returns a result, but rows are not ordered in descending order. How can I do that?"). We'll gladly help!
Reply With Quote
  #3 (permalink)  
Old 10-12-07, 11:02
Guldan Guldan is offline
Registered User
 
Join Date: Oct 2007
Posts: 3
Quote:
Originally Posted by Littlefoot
Basically, CREATE TABLE and INSERT INTO statements are always welcome - those will help other Forum members to create a testing environment.

However, it is not our job to do your homework. You won't benefit from a complete solution as you won't learn anything from it. The right way to do this task is: YOU do the coding. Run it, correct syntax errors and come back to ask a question about the SPECIFIC problem you have (for example, "query returns a result, but rows are not ordered in descending order. How can I do that?"). We'll gladly help!

I understand, but now my assignment is due in 2 hrs and its not done. my view is creating but I have idea if its right.. ive gotten nowhere, wouldve been nice if someone could point me in the right direction
Reply With Quote
  #4 (permalink)  
Old 10-12-07, 11:28
shammat shammat is offline
Registered User
 
Join Date: Nov 2003
Posts: 654
Quote:
Originally Posted by Guldan
my view is creating but I have idea if its right..
Show us the view, and maybe we can spot any problems.
Reply With Quote
  #5 (permalink)  
Old 10-12-07, 11:57
Guldan Guldan is offline
Registered User
 
Join Date: Oct 2007
Posts: 3
Quote:
Originally Posted by shammat
Show us the view, and maybe we can spot any problems.

CREATE VIEW Running_Total AS
SELECT g.guestNo, g.guestName, g.guestAddress, r.price*(b.dateTo - b.dateFrom) AS S1
FROM guest g, booking b, hotel h, room r
WHERE g.guestNo = b.guestNo AND
r.roomNo = b.roomNo AND
b.hotelNo = h.hotelNo AND
h.hotelName = 'Grosvenor Hotel' AND
b.dateFrom = '2007-10-09';


I dont know what im doing... lol. SQL is tough

to DISPLAY it dont I just

SELECT *
FROM Running_Total
Reply With Quote
  #6 (permalink)  
Old 10-12-07, 13:00
chuck_forbes chuck_forbes is offline
Registered User
 
Join Date: Dec 2003
Posts: 848
Sounds to me like you've done everything correctly. If it were me, I'd leave out the

Code:
h.hotelName = 'Grosvenor Hotel' AND b.dateFrom = '2007-10-09'

from the VIEW def'n, and include that only in queries against the view. Otherwise, you have to create a separate view for every hotel/dateFrom combination

Code:
CREATE VIEW Running_Total AS SELECT h.hotelName, b.dateFrom, g.guestNo, g.guestName, g.guestAddress, r.price*(b.dateTo - b.dateFrom) AS S1 FROM guest g, booking b, hotel h, room r WHERE g.guestNo = b.guestNo AND r.roomNo = b.roomNo AND b.hotelNo = h.hotelNo SELECT * FROM Running_Total WHERE h.hotelName = 'Grosvenor Hotel' AND b.dateFrom = '2007-10-09'
Reply With Quote
  #7 (permalink)  
Old 10-12-07, 16:40
Littlefoot Littlefoot is offline
Lost Boy
 
Join Date: Jan 2004
Location: Croatia, Europe
Posts: 2,717
However, I'd rather not mix dates and strings as in
Code:
b.dateFrom = '2007-10-09'
but use proper datatype conversion:
Code:
b.dateFrom = TO_DATE('2007-10-09', 'yyyy-mm-dd')
Reply With Quote
  #8 (permalink)  
Old 10-12-07, 16:56
chuck_forbes chuck_forbes is offline
Registered User
 
Join Date: Dec 2003
Posts: 848
Yeppers, good point ... my bad ... for not seeing that. ---=cf
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

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