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

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...
Describe the functions provided by a relational database that could be used to record courses taken...
Describe the functions provided by a relational database that could be used to record courses taken by university students in order to manage scheduling and preparing transcripts. Please respond with 200-250 words. Thanks
Assume that you have a Saudi league player database. In this database, you have a table...
Assume that you have a Saudi league player database. In this database, you have a table containing players’ attributes such as (Name, age, position, etc.) and you decided to add information about players’ agents. Would you represent the agent information as attributes in the player table or would you create an entity set for players’ agents? Justify your answer.   I need clear answer please don't copy and paste
Assume that you have a Saudi league player database. In this database, you have a table containing players’ attributes
Assume that you have a Saudi league player database. In this database, you have a table containing players’ attributes such as (Name, age, position, etc.) and you decided to add information about players’ agents. Would you represent the agent information as attributes in the player table or would you create an entity set for players’ agents? Justify your answer.
You have been appointed as the new general manager of a named hotel. The hotel is...
You have been appointed as the new general manager of a named hotel. The hotel is not performing as expected and is not meeting its target. Your first assignment is to resolve this problem. Describe in details how you would go about addressing this problem. Hint: Describe the data collection approaches you would use (Observation, interviews, surveys, historical research (past 5 years), etc.) and why you chose this specific form of data collection etc.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT