DBMS 8th Assignment
DBMS 8th Assignment
CATLOG(book-id: int, title : string, author-id: int, publisher-id: int, category: int, year:
i) Create above tables by properly specifying the primary keys and the foreign keys.
create table author(author_id number primary key, name varchar2(50), city varchar2(50), country
varchar2(50));
create table publisher(publisher_id number primary key, name varchar2(50), city varchar2(50), country
varchar2(50));
create table catlog(book_id number primary key, title varchar2(50), author_id number, publisher_id
number, category number, year number, price number, foreign key(author_id) references
author(author_id), foreign key(publisher_id) references publisher(publisher_id));
create table order_details(order_no number primary key, book_id number, quantity number, foreign
key(book_id) references catlog(book_id));
Output:
Table created.
Table created.
Table created.
Table created.
Table created.
Output:
1 row(s) inserted.
1 row(s) inserted.
1 row(s) inserted.
1 row(s) inserted.
1 row(s) inserted.
1 row(s) inserted.
1 row(s) inserted.
1 row(s) inserted.
1 row(s) inserted.
1 row(s) inserted.
1 row(s) inserted.
1 row(s) inserted.
1 row(s) inserted.
1 row(s) inserted.
1 row(s) inserted.
1 row(s) inserted.
1 row(s) inserted.
1 row(s) inserted.
1 row(s) inserted.
1 row(s) inserted.
1 row(s) inserted.
1 row(s) inserted.
1 row(s) inserted.
1 row(s) inserted.
1 row(s) inserted.
iii) Give the details of the authors 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 2010.
select a.* from author a where a.author_id in(select c.author_id from catlog c group by c.author_id
having count(c.book_id)>=2 and max(c.price)>(select avg(price) from catlog) and min(c.year)>2010);
Output:
iv) Find the author of the book which has maximum sales.
select a.name as author,c.title as book_name from author a inner join (catlog c inner join order_details o
on o.book_id=c.book_id) on a.author_id=c.author_id where quantity=(select max(quantity) from
order_details);
Output:
Output: