0% found this document useful (0 votes)
482 views6 pages

Insert and Query To Bookshop Database System

The document provides SQL scripts to insert data into and query a BookShop database. It includes inserts for publishers, authors, books, customers, warehouses and shopping baskets. It also lists 5 sample queries to find the best selling book, top customer, warehouse with a specific book, most prolific author, and publisher with fewest books.

Uploaded by

Siddharth Tandon
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
482 views6 pages

Insert and Query To Bookshop Database System

The document provides SQL scripts to insert data into and query a BookShop database. It includes inserts for publishers, authors, books, customers, warehouses and shopping baskets. It also lists 5 sample queries to find the best selling book, top customer, warehouse with a specific book, most prolific author, and publisher with fewest books.

Uploaded by

Siddharth Tandon
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

 

 
Insert and Query to BookShop database system

SOLUTION

DOCUMENTS  TO  BE  DELIVERED:  


A) SQL  SCRIPT  WITH  DDL    INSERTS  AND  QUERIES  TO  THE  BOOKSHOP  DATABASE  
 
Inserts  to  tables:  
use  bookshop;  
 
insert  into  Publisher  (Publisherid,  PublisherName,  PublisherAddress,  PublisherPhone,  URL)  
values(01,  'Penguin  Random  House',  'Luchana  23  Madrid  
Spain',535819,'http://www.penguinrandomhouse.com/');  
insert  into  Publisher  (Publisherid,  PublisherName,  PublisherAddress,  PublisherPhone,  URL)  
values(02,  'Hachette  Livre','50  Victoria  Embankment',227000,  'https://www.hachette.com');  
insert  into  Publisher  (Publisherid,  PublisherName,  PublisherAddress,  PublisherPhone,  URL)  
values(03,  'HarperCollins','The  News  Building  London  Bridge  
Street',2427737,'https://www.harpercollins.com/');  
insert  into  Author  values  (01,'Cat  Sebastian','9296  Henry  St.  Auburndale  FL  33823');  
insert  into  Author  values  (02,'Lorraine  Heath','974  Broad  Dr.  Marcus  Hook  PA  19061');  
insert  into  Author  values  (03,'Jill  Shalvis','187  Cherry  Rd.  Reston  VA  20191');  
insert  into  Author  values  (04,'Kevin  Kwan','13  Locust  St.  Round  Lake  IL  60073');  
insert  into  Author  values  (05,'Elisabeth  Noreback','26  Rock  Creek  Dr.  Tuscaloosa  AL  35405');  
insert  into  Author  values  (06,'Pamela  Brown',  '409  Santa  Clara  Ave.  Cedar  Rapids  IA  52402');  
insert  into  Book  (isbn,  title,  year,price,  publisherid,  authorid)  values  ('9706279318','A  Gentleman  
Never  Keeps  Score',2018,384.00,03,01);  
insert  into  Book  (isbn,  title,  year,price,  publisherid,  authorid)  values  ('9728304828','Texas  
Glory',2015,94.50,03,02);  
insert  into  Book  (isbn,  title,  year,price,  publisherid,  authorid)  values  ('9702833373','Rainy  day  
friends',2017,45.00,03,03);      
insert  into  Book  (isbn,  title,  year,price,  publisherid,  authorid)  values  ('9703859383','Crazy  Rich  
Asians',2018,234.50,01,04);  
insert  into  Book  (isbn,  title,  year,price,  publisherid,  authorid)  values  ('9793937483','Tell  me  you  are  
mine',2015,23.60,01,05);  
insert  into  Book  (isbn,  title,  year,price,  publisherid,  authorid)  values  ('9729473047','The  spy  and  
the  traitor',  2010,200.00,01,  05);  
insert  into  Book  (isbn,  title,  year,price,  publisherid,  authorid)  values  ('9703746264','Paradise  Sky  by  
Joe  Lansdale',2016,145.00,02,06);  
insert  into  Book  (isbn,  title,  year,price,  publisherid,  authorid)  values  ('9739482733','Meet  Camaro  
from  The  Night  Charter',2010,165.99,02,06);      
 

insert  into  Customer  values  ('[email protected]','Karol  Wilson',  115099561,  '75  Poplar  Court  
Eugene  OR  97402');  
insert  into  Customer  values  ('[email protected]','Richard  Orson',  45528305,  '33  Richardson  Dr.  
Chandler  AZ  85224');  
insert  into  Customer  values  ('[email protected]','Loraine  Williams',  2211600,'8  Market  St.  
Portsmouth  VA  23703');  
insert  into  Customer  values  ('[email protected]','Scott  Luka',  649373,'412  Pawnee  Lane  Kenosha,  WI  
53140');  
insert  into  Warehouse  values  (01,  5393544,'530  Roosevelt  Lane  Hopewell  Junction  NY  12533');  
insert  into  Warehouse  values  (02,  9759583,'9592  Applegate  Road  Bedford  OH  44146');  
insert  into  Warehouse  values  (03,  9958484,'21  Arch  Ave.  Grand  Haven  MI  49417');  
insert  into  shoppingbasket  values  (01,'[email protected]');  
insert  into  shoppingbasket  values  (02,'[email protected]');  
insert  into  shoppingbasket  values  (03,'[email protected]');  
insert  into  shoppingbasket  values  (04,'[email protected]');  
 
insert  into  shoppingbaskets_have_books  values('9706279318',01,1);  
insert  into  shoppingbaskets_have_books  values('9703746264',01,1);  
insert  into  shoppingbaskets_have_books  values('9729473047',01,1);    
 
insert  into  shoppingbaskets_have_books  values('9739482733',02,1);  
insert  into  shoppingbaskets_have_books  values('9728304828',02,1);  
insert  into  shoppingbaskets_have_books  values('9702833373',02,2);  
insert  into  shoppingbaskets_have_books  values('9703859383',02,1);  
 
insert  into  shoppingbaskets_have_books  values('9793937483',03,1);  
insert  into  shoppingbaskets_have_books  values('9703859383',03,1);  
insert  into  shoppingbaskets_have_books  values('9702833373',03,1);  
 
insert  into  shoppingbaskets_have_books  values('9739482733',04,1);  
insert  into  shoppingbaskets_have_books  values('9702833373',04,1);  
insert  into  shoppingbaskets_have_books  values('9729473047',04,1);  
insert  into  shoppingbaskets_have_books  values('9793937483',04,1);  
 
insert  into  warehouses_have_books  (warehouse_code,Book_ISBN,count)  
values(01,'9728304828',15);  
insert  into  warehouses_have_books  (warehouse_code,Book_ISBN,count)  
values(01,'9739482733',29);  
insert  into  warehouses_have_books  (warehouse_code,Book_ISBN,count)  
values(01,'9729473047',151);  
 
insert  into  warehouses_have_books  (warehouse_code,Book_ISBN,count)  
values(02,'9703859383',20);  
 

insert  into  warehouses_have_books  (warehouse_code,Book_ISBN,count)  


values(02,'9793937483',383);  
insert  into  warehouses_have_books  (warehouse_code,Book_ISBN,count)  
values(02,'9706279318',293);  
 
insert  into  warehouses_have_books  (warehouse_code,Book_ISBN,count)  
values(03,'9702833373',393);  
insert  into  warehouses_have_books  (warehouse_code,Book_ISBN,count)  
values(03,'9729473047',38);  
insert  into  warehouses_have_books  (warehouse_code,Book_ISBN,count)  
values(03,'9706279318',48);  
insert  into  warehouses_have_books  (warehouse_code,Book_ISBN,count)  
values(03,'9739482733',29);  
 
QUERIES  
1) Which book is being sell more right now?
select book_isbn, title,sum(count) as maxbooks from book B,
shoppingbaskets_have_books SB
where SB.book_isbn=B.isbn
group by book_isbn, title
order by maxbooks desc
LIMIT 1

2) Which customer is buying more books?


select maxnumber, Customer
from (select sum(count) as maxnumber, customerName as Customer
from customer C, shoppingbasket SB,shoppingbaskets_have_books SBB
where C.customerEmail=SB.customerEmail
and SB.shoppingBasketid=SBB.shoppingBasketid
group by customerName
order by maxnumber desc) mysums
LIMIT 1

3) Which warehouse has Texas Glory in stock?


select code, warehouseAddress
from warehouse W, warehouses_have_books WB, book B
where W.code=WB.warehouse_code
and WB.book_isbn = B.isbn
and title = 'Texas Glory'

4) Which author has more books on sell?


select AuthorName,count(title) as numberbooks
from author A, book B
where A.authorid=B.authorid
group by AuthorName
order by numberbooks desc
LIMIT 1
 

5) Which publisher offers less books?


select PublisherName, count(title) as numberofbooks
from Publisher P, Book B
where P.publisherid=B.publisherid
group by publisherName
order by numberofbooks desc
LIMIT 1
 

B) DOCUMENT  WITH  PRINT  SCREENS  OF  THE  EXECUTION  AND  QUERY  RESULTS.  
 

 
 
 

 
 

 
 
 

 
 
 

 
 

 
 
 

You might also like