Prog 4
Prog 4
AUTHOR(author-id:int,name:string,city:string,country:string)
PUBLISHER(publisher-id:int,name:string,city:string,country:string)
CATALOG(book-id:int,title:string,author-id:int,publisher-id:int,category-id:int,price:int)
CATEGORY(category-id:int,description:string)
ORDER-DETAILS(order-no:int,book-id:int,quantity:int)
1)create the above tables by properly specifying the primary keys and the foreign keys..
2)enter atleast five tuples for each relation.
3)give the details of the author who have 2 or more books in the catalog and the price of the
books is greater than the average price of the books in the
catalog and the year of publication is after 2000.
4)find the author of the book which has maximum sales..
5)demonstrate how you increase the price of books published by a specific publisher by 10%.
TABLE CREATION:
1.AUTHOR TABLE
2.PUBLISHER TABLE
CREATE TABLE PUBLISHER
(
PUBLISHER_ID NUMERIC(5) PRIMARY KEY,
PNAME VARCHAR(10),
PCITY VARCHAR(10),
PCOUNTRY VARCHAR(10)
);
3.CATEGORY TABLE
CREATE TABLE CATEGORY
(
CATEGORY_ID NUMERIC(5) PRIMARY KEY,
DESCRIPTION VARCHAR(10)
);
4.CATALOG TABLE
5.ORDER-DETAILS TABLE
1.INSERT TO AUTHOR
Insert into author values(100,'Amar','Blore','India');
Insert into author values(200,'Ashish','alaska','USA');
Insert into author values(300,'Sanjith','california','USA');
Insert into author values(400,'Mohit','Birmingham','UK');
Insert into author values(500,'Laxmi','Delhi','India');
2.INSERT TO PUBLISHER
Insert into publisher values(11,'Wiely','New Delhi','India');
Insert into publisher values(22,'Pearson','California','USA');
Insert into publisher values(33,'Godse','Bangalore','India');
Insert into publisher values(44,'Folley','New York','USA');
Insert into publisher values(55,'tenenbm','Texas','USA');
3.INSERT TO CATEGORY
4.INSERT TO CATALOG
5.INSERT TO ORDER-DETAILS
TABLE CONTENTS:
AUTHOR TABLE
PUBLISHER TABLE
CATEGORY TABLE
CATEGORY_ID DESCRIPTIO
------------ --------------
1 low price
2 best sell
3 Hardware
4 Algorithms
5 Internet
CATALOG TABLE
ORDER-DETAILS TABLE
//give the details of the author who have 2 or more books in the catalog and the price of the
books is greater than the average price of the books in the
catalog and the year of publication is after 2000//
SOLUTION:
SELECT AUTHOR_ID,ANAME,CITY,COUNTRY
FROM AUTHOR
WHERE AUTHOR_ID IN(
SELECT A.AUTHOR_ID
FROM AUTHOR A,CATALOG C,ORDER_DET O
WHERE A.AUTHOR_ID=C.AUTHOR_ID AND C.BOOK_ID=O.BOOK_ID AND
QUANTITY>=2 AND YEAR>2000 AND PRICE>(
SELECT AVG(PRICE)
FROM CATALOG)
GROUP BY A.AUTHOR_ID);
SOLUTION:
select * from catalog;
SELECT A.AUTHOR_ID,A.ANAME,C.TITLE,O.BOOK_ID,O.QUANTITY
FROM AUTHOR A,CATALOG C,ORDER_DET O
WHERE A.AUTHOR_ID=C.AUTHOR_ID AND C.BOOK_ID=O.BOOK_ID AND
O.QUANTITY=( SELECT MAX(QUANTITY)
FROM ORDER_DET);
SOLUTION:
select * from catalog;