Question

In: Computer Science

We have provided you the Hotel database to be used with SQLite DBMS. You should use...

We have provided you the Hotel database to be used with SQLite DBMS. You should use this database in SQLite to extract the necessary information as per the following query requirements.

The sqlite script is based on the following relational schema:

•Hotel (hotelNo, hotelName, city)

• Room (roomNo, hotelNo, type, price)

• Booking (hotelNo, guestNo, dateFrom, dateTo, roomNo)

•Guest (guestNo, guestName, guestAddress)

Note the following details of the hotel database;

•Hotel contains hotel details and hotelNo is the primary key;

•Room contains room details for each hotel and (roomNo, hotelNo) forms the primary key;

•Booking contains details of bookings and (hotelNo,guestNo,dateFrom) forms the primary key;

•Guest contains guest details and guestNo is the primary key.

Write an SQLite script for querying data.

•List hotelNo, type and price of each double or deluxe room with a price more than $99.

•List hotelNo who have more than 2 double rooms.

•List number of different guests who visited Ridge Hotel.

•What is the total income from bookings for the Grosvenor Hotel? .

•List all the guests who have stayed in a hotel.

Task 3 [3 marks]

Perform the following tasks.

•Write commands to insert rows in each of the Hotel database tables .

•Write a command to delete the row you inserted in the table Guest .

•Write a command to update the price of all rooms by 10% (1 mark).

Solutions

Expert Solution

1. List hotelNo, type and price of each double or deluxe room with a price more than $99(2 marks).

Answer: INNER JOIN is required here, so joining of 2 tables, Hotel and Room is required on hotelNo to list the hotelNo, type and price with roomtype as double or deluxe.

select hotelNo, type, price from

Hotel JOIN Room on Hotel.hotelNo = Room.HotelNo

where (Room.type= 'double' OR Room.type='deluxe') and price > 99;

2. List hotelNo who have more than 2 double rooms(2 marks).

Answer: GROUPBY clause is required here to group rows based on Room.hotelNo and aggregate function count(hotelNo) to identify hotel with more than 2 double rooms.

select hotelNo from Room where roomType='double' GROUP BY hotelNo HAVING COUNT(hotelNo) > 2;

3. List number of different guests who visited Ridge Hotel(3 marks).

Answer: Subquery is required to identify hotelNo where hotel name is Ridge in Hotel table. Aggregate function COUNT() is required here to identify the number of guests from Booking table.

select COUNT(guestNo) from Booking where hotelNo = (select hotelNo from Hotel where hotelNo='Ridge');

4. What is the total income from bookings for the Grosvenor Hotel? (4 marks).

Answer: Here first subquery is required to identify the HotelNo with hotelName as "Grosvenor". Secondly aggregate function SUM() is required to identify the total income from bookings.

select SUM(Room.price) from Booking Join Room on Booking.hotelNo = Room.hotelNo where

Booking.hotelNo=(select Room.HotelNo from Room Join Hotel on Hotel.hotelNo=Room.hotelNo where Hotel.hotelName = 'Grosvenor');

5. List all the guests who have stayed in a hotel(4 marks).

Answer: INNER JOIN is required on Guest and Booking table on guestNo to identify the list of guestNo, guestName and keyword DISTINCT is required to identify the unique Guest.

select distinct Guest.guestNo, Guest.guestName from Guest JOIN Booking on Guest.guestNo = Booking.guestNo;

As per Chegg guidelines, when multiple questions are part of one single question, initial 4 questions needs to be answered, I have answered the first part of question with 5 sub questions.


Related Solutions

1.6. Discuss the capabilities that should be provided by a DBMS. 1.7. Discuss the differences between...
1.6. Discuss the capabilities that should be provided by a DBMS. 1.7. Discuss the differences between database systems and information retrieval systems.
SQL DATABASE Task 2 [10.5 marks] using the AdditionCollege database For task 2, we have provided...
SQL DATABASE Task 2 [10.5 marks] using the AdditionCollege database For task 2, we have provided you with the creation script for the AdditionCollege database. Run this script in MySQL Workbench to create the database. You should execute your query solutions to extract the necessary information. The script is based on the following schematic: Unit (Unit_code, Staff_id, [UnitName]) Staff (Staff_id, StaffName, Position, Gender) Taught_by (Unit_code, Staff_id, weekday) Student (Student_id, Student_name, Address, Gender) TuteGroup (TuteGroup_code, Unit_code, DayHrCode, Room_Nr) TuteGroup_List (TuteGroup_code, Student_id)...
14.19. Suppose that we have the following requirements for a university database that is used to...
14.19. Suppose that we have the following requirements for a university database that is used to keep track of students’ transcripts: a. The university keeps track of each student’s name (Sname), student number (Snum), Social Security number (Ssn), current address (Sc_addr) and phone (Sc_phone), permanent address (Sp_addr) and phone (Sp_phone), birth date (Bdate), sex (Sex), class (Class) (‘freshman’, ‘sophomore’, … , ‘graduate’), major department (Major_code), minor department (Minor_code) (if any), and degree program (Prog) (‘b.a.’, ‘b.s.’, … , ‘ph.d.’). Both...
For this assignment, you will use the provided database in the Unit 5 script file. You...
For this assignment, you will use the provided database in the Unit 5 script file. You will add statements to this file to query the database tables. For your reference, below is a screenshot of the enhanced entity relationship diagram (ERD) as a reference when you write your queries. With the data types listed in the diagram, this will help you identify the types of operators that you can use for particular queries. Use paiza.io for MySQL to execute and...
QUESTION 71 For first name column in our subsidiary’s database in Japan, we should use _____...
QUESTION 71 For first name column in our subsidiary’s database in Japan, we should use _____ A. nchar(30) B. char(30) C. varchar(30) D. nvarchar(30) QUESTION 72 for column definition of middle name in US., we should use _____ A. nchar(20) B. char(20) C. varchar(20) D. varchar2(20)
PROBLEM In the Hotel management domain, we have the following concepts: Hotel Hotel chain Hotel room  ...
PROBLEM In the Hotel management domain, we have the following concepts: Hotel Hotel chain Hotel room       Reservation Hilton Hilton San Diego Bayfront Meeting room Ballroom Guest Room Catering Service Internet Service       TV Service Guest Parking Service       Item on bill       You are asked to design a model, using a UML class diagram to relate the abovementioned concepts: Correctly use UML notations for relations such as generalization, association, aggregation, composition. Be careful to distinguish objects from classes. You...
the mysql lyrics database is provided below 1.)What is a primary key used for? Can you...
the mysql lyrics database is provided below 1.)What is a primary key used for? Can you give me an example of a primary key in the Lyrics database? 2.)What is the purpose of doing a join between two tables. Ex. Why would I ever want to join the Tracks and Titles tables together? 3.)Why is isolation important in database design? DROP TABLES IF EXISTS Artists,Genre, Members, Titles, Tracks,SalesPeople,Studios,XrefArtistsMembers; DROP TABLES IF EXISTS Authors,Publishers,Titles,Title_Authors,Royalties; DROP TABLES IF EXISTS Products,Customers,Orders,Order_details; DROP TABLES...
(Q)Choose a DBMS that you’d like to use. Provide some evidences to show that you have...
(Q)Choose a DBMS that you’d like to use. Provide some evidences to show that you have some basic knowledge of the software. For instance, use the software to define a name and address database of your business associates, friends, classmates etc. You can use the following relation: (LAST NAME, FIRST NAME, SEX, ADDRESS, POSTCODE, CITY, PHONE). Enter at least five people in your data file. Print/screen shot a copy of the records. There should be no blank records. (20) please...
We use the WMCRM database and here is the summary of the database schema (where schema...
We use the WMCRM database and here is the summary of the database schema (where schema is used in its meaning of a summary of the database structure): VEHICLE (InventoryID, Model, VIN) SALESPERSON (NickName, LastName, FirstName, HireDate, WageRate, CommissionRate, OfficePhone, EmailAddress, InventoryID) CUSTOMER (CustomerID, LastName, FirstName, Address, City, State, ZIP, EmailAddress, NickName) PHONE_NUMBER (CustomerID, PhoneNumber, PhoneType) CONTACT(ContactID, CustomerID,ContactDate,ContactType,Remarks) Where InventoryID in SALESPERSON must exist in InventoryID in VEHICLE NickName in CUSTOMER must exist in NickName in SALESPERSON CustomerID in PHONE_NUMBER...
Design a simple database to track people and who they voted for. The database should have...
Design a simple database to track people and who they voted for. The database should have 3 tables: A table of candidates A table of registered voters A table of votes The candidate table should provide a listing of all candidates and information about the candidates. The registered voter table should hold all registered voters and any pertinent information about them The vote table should hold vote records for each candidate made by the voters Requirements: The system should not...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT