Question

In: Computer Science

Using the HotelDB tables, provide the following result as a screen image. WRITE SQL to retrieve...

Using the HotelDB tables, provide the following result as a screen image.

WRITE SQL to retrieve rows from any hotel with Family room types and price less than $150.

use hoteldb;
CREATE TABLE HOTEL
( hotelNo numeric primary key
, name varchar(40)
, address varchar(40)
, city varchar(200)
);
CREATE TABLE ROOM
( roomNo numeric Primary Key
, hotelNo numeric References HOTEL
, type varchar(20)
, price dec(9,2)
);

CREATE TABLE GUEST
( guestNo numeric primary key
, name varchar(40)
, address varchar(40)
);

CREATE TABLE BOOKING
( hotelNo numeric REFERENCES Hotel
, guestNo numeric REFERENCES Guest
, dateFrom date NOT NULL
, dateTo date
, roomNo numeric REFERENCES ROOM
);

INSERT INTO HOTEL VALUES (1,'Hilton Hotel','123 Main st','New Jersey');
INSERT INTO HOTEL VALUES (2,'Holiday Inn','50 3rd Ave.', 'New York');
INSERT INTO HOTEL VALUES (3,'Governor Hotel','8243 Berkley Sq.','London');
INSERT INTO HOTEL VALUES (4,'New World Hotel','30 East River Rd', 'Hong Kong');
INSERT INTO HOTEL VALUES (5,'Santos Hotel','15 Main Rd', 'Philippines');

insert into room values (1,1,'Family',200);
insert into room values (2,1,'Family',200);
insert into room values (3,1,'Single',100);
insert into room values (4,1,'Single',100);
insert into room values (5,2,'Family',80);
insert into room values (6,2,'Family',85);
insert into room values (7,2,'Family',80);
insert into room values (8,3,'Single',35);
insert into room values (9,3,'Double',115);
insert into room values (10,3,'Double',115);
insert into room values (11,3,'Family',150);
insert into room values (12,4,'Single',30);
insert into room values (13,4,'Single',30);
insert into room values (14,4,'Single',30);
insert into room values (15,4,'Double',90);
insert into room values (16,4,'Double',90);
insert into room values (17,4,'Double',90);
insert into room values (18,4,'Family',110);
insert into room values (19,4,'Family',110);
insert into room values (20,5,'Double',38);
insert into room values (21,5,'Double',38);
insert into room values (22,5,'Single',32);
insert into room values (23,5,'Single',32);

insert into guest values (1,'John Doe','Los Angeles');
insert into guest values (2,'Mary Jane','New York');
insert into guest values (3,'Hank Kim','London');
insert into guest values (4,'Bob Jones','London');
insert into guest values (5,'Paul John','New York');
insert into guest values (6,'Ann Smith','New York');
insert into guest values (7,'James Mann','London');
insert into guest values (8,'Mary Mann','London');
insert into guest values (9,'Jim Jones','New York');
insert into guest values (10,'Tom Jones','Los Angeles');
insert into guest values (11,'Jimmy Johnson','Boston');
insert into guest values (12,'Harry Coleman','Dallas');
insert into guest values (13,'Bob James','Los Angeles');
insert into guest values (18,'John Mary','London');
insert into guest values (21,'Jeff Bridges','London');
insert into guest values (23,'Larry Cohen','New York');

Solutions

Expert Solution

The following screen image is the result of the commands that are written in order to use the database hotel IDB and the creation of four tables HOTEL, ROOM, GUEST and BOOKING along with their individual records as written in INSERT statement as given in the question.

The screen image of all for table creation along with their entity is attached below.

In order to fetch the entire row from any hotel that are having the FAMILY room type and price less than 150 dollars then it use both the HOTEL and ROOM table which is interlinked by the NATURAL JOIN as associated with the hotel number(hotelNo).

The condition applied in WHERE clause where type of room table is family and price of room table is less than $150.

It also use AND operator so that when both the condition are satisfied true then only the data retrieved.

Along with that, the entire row of the hotel details is fetched from HOTEL table and the output of the given query is also attached with screen image.

The SQL command is:

Select hotel.hotelNo, hotel.name, hotel.address, hotel.city from HOTEL NATURAL JOIN ROOM where ROOM.type="Family" AND ROOM.Price<150;


Related Solutions

Write the SQL DDL to create the following 5 tables for an App store: Publisher, Category,...
Write the SQL DDL to create the following 5 tables for an App store: Publisher, Category, App, AppVersion, AppVersionReview: A Publisher table where each publisher is identified by an integer id and has a name (up to 40 characters). (1 mark) A Category table where each category has an id (integer), a name (up to 50 characters), and a parentId to identify its parent category. The parentId should be a foreign key to the Category table. (1.5 marks) An App...
1. write SQL statements to create the following two tables: a) Department table that contains the...
1. write SQL statements to create the following two tables: a) Department table that contains the following columns(dept_no,deptname,location) set the deptno to be the primary key. b) Employee table contains the following columns(emp_no,empname,deptno,salary)set the emp_no to be the primary key and dept_no to be the foreign key. 2. Write SQL statements to Insert the following 3 rows in Employee table:        (101,’Sami’,’D-101’,5000)        (102,’Yousef’,’D-101’,4000)        (103,’Sami’,’D-102’,7000) 3. Write SQL statements to Insert the following 3 rows in Department table:       ...
Based on the tables below, write SQL command to perform the following tasks for MySql: Create...
Based on the tables below, write SQL command to perform the following tasks for MySql: Create SALESREP and CUSTOMER tables Create primary and foreign keys as appropriate. The custNo should use a surrogate key as the primary key with auto-increment increase the balance of the Gonzales account by $100 to a total of $450? Find an average customer balance Display the name of the sales representative and the name of the customer for each customer that has a balance greater...
pros and cons of using a drain rooter with live image with handheld screen or using...
pros and cons of using a drain rooter with live image with handheld screen or using a drain rooter device with smartphone.
​​​​​​ Write a SQL statement to retrieve user account information (username, account_status, default_tablespace, temporary_tablespace, and created...
​​​​​​ Write a SQL statement to retrieve user account information (username, account_status, default_tablespace, temporary_tablespace, and created date) of your account. Write a SQL statement to retrieve the “USERS” table space information (tablespace name, block_size, initial extent, max_extents). Write a SQL statement to retrieve the physical file information (file name, tablespace name, bytes, blocks, and status).  
Using SQL Developer Question 1 Create a block to retrieve and display pledge and payment information...
Using SQL Developer Question 1 Create a block to retrieve and display pledge and payment information for a specific donor. For each pledge payment from the donor, display the pledge ID, pledge amount, number of monthly payments, payment date, and payment amount. The list should be sorted by pledge ID and then by payment date. For the first payment made for each pledge, display “first payment” on that output row. Question 2 Redo question 1, but use a different cursor...
Use the following information to create SQL commands to retrieve data from Henry Books database :...
Use the following information to create SQL commands to retrieve data from Henry Books database : For each book, list the book code, book title, publisher code, and publisher name. Order the results by publisher name. For each book published by Plume, list the book code, book title, and price. List the book title, book code, and price of each book published by Plume that has a book price of at least $14. List the book code, book title, and...
Write the SQL queries that accomplish the following tasks using the AP Database 9. Write a...
Write the SQL queries that accomplish the following tasks using the AP Database 9. Write a select statement to show the invoicelineitemdescriptions that have the total invoicelineitemamount >1000 and the number of accountno is >2. 10. Write a select statement that returns the vendorid, paymentsum of each vendor, and the number of invoices of each vendor, where paymentsum is the sum of the paymentotal column. Return only the top ten vendors who have been paid the most and the number...
Create three MySQL database tables and write SQL scripts to read, insert, and delete data. The...
Create three MySQL database tables and write SQL scripts to read, insert, and delete data. The first database table will contain the names of at least four movies. The second table will be a list of actors who appear in the movies. The third table will be an associative table that describes the relationship between the actors and their movies (which actors appear in which movies). Actors and movies have a “many-to-many relationship,” meaning an actor can be in multiple...
Create three MySQL database tables and write SQL scripts to read, insert, and delete data. The...
Create three MySQL database tables and write SQL scripts to read, insert, and delete data. The first database table will contain the names of at least four movies. The second table will be a list of actors who appear in the movies. The third table will be an associative table that describes the relationship between the actors and their movies (which actors appear in which movies). Actors and movies have a “many-to-many relationship,” meaning an actor can be in multiple...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT