Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use SQL to specify the following queries: 1) Retrieve the customers' names who bought the book type 'Novel'. Order the result in the descending order

Use SQL to specify the following queries:

1) Retrieve the customers' names who bought the book type 'Novel'. Order the result in the descending order of customer name

Here are the relative create table statements and populate table statements that I have already done:

CREATE TABLE Customer ( cid CHAR(9) NOT NULL, name VARCHAR(20), address VARCHAR(80), PRIMARY KEY (cid) );

CREATE TABLE Orders ( oid CHAR(9) NOT NULL, order_date DATE, cid CHAR(9), PRIMARY KEY (oid) );

CREATE TABLE Book ( isbn CHAR(10) NOT NULL, title VARCHAR(100), btype VARCHAR(15), price DECIMAL(10,2), pub_date DATE, pid CHAR(10), PRIMARY KEY(isbn) );

CREATE TABLE Order_book ( oid CHAR(9), isbn CHAR(10), no_of_copy INT, CONSTRAINT fk_oid FOREIGN KEY(oid) REFERENCES Orders(oid), CONSTRAINT fk_isbn FOREIGN KEY(isbn) REFERENCES Book(isbn) );

INSERT INTO customer (cid, name, address) VALUES ('1', 'Mike Kay', '4914 Percheron Drive, Elk Grove, CA');

INSERT INTO book (isbn, title, btype, price, pub_date, pid) VALUES ('8330418998', 'Fundamentals of Database Systems', 'Textbook', 10.50, '2008-07-04', '200');

INSERT INTO book (isbn, title, btype, price, pub_date, pid) VALUES ('1234567890', 'Yes Man', 'Novel', 12.50, '2010-11-04', '200');

INSERT INTO book (isbn, title, btype, price, pub_date, pid) VALUES ('9210321309', 'Elenaor', 'Novel', 9.50, '2015-12-17', '200');

INSERT into orders (oid, order_date, cid) VALUES ('1', '2016-10-23', '1');

INSERT into orders (oid, order_date, cid) VALUES ('2', '2011-01-25', '1');

INSERT into orders (oid, order_date, cid) VALUES ('3', '2000-09-13', '1');

INSERT into orders (oid, order_date, cid) VALUES ('4', '2000-09-13', '1');

INSERT INTO order_book (oid, isbn, no_of_copy) VALUES ('1', '8330418998', 5);

INSERT INTO order_book (oid, isbn, no_of_copy) VALUES ('2', '1234567890', 1);

INSERT INTO order_book (oid, isbn, no_of_copy) VALUES ('3', '9210321309', 1);

INSERT INTO order_book (oid, isbn, no_of_copy) VALUES ('4', '2148481540', 1);

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Principles Of Multimedia Database Systems

Authors: V.S. Subrahmanian

1st Edition

1558604669, 978-1558604667

More Books

Students also viewed these Databases questions