RSR Manual 3
RSR Manual 3
Schema Diagram
Entity-Relationship Diagram
Table Creation
create table publisher( pname varchar(10) ,
address varchar(10),
phoneno int,
primary key(pname));
1. Retrieve details of all books in the library – id, title, name of publisher, authors, number of copies in
each branch, etc.
2. Get the particulars of borrowers who have borrowed more than 3 books, but from Jan 2017 to Jun
2017.
select cardno
from booklend
where dateout between '01-jan-2017' and '01-jul-2017'
group by cardno
having count(*)>3;
4. Partition the BOOK table based on year of publication. Demonstrate its working with a simple
query.
create view v1 AS
select puyear
from book
order by puyear;
5. Create a view of all books and its number of copies that are currently available in the Library.
create view v2 AS
select b.bookid, b.tittle,c.noofcopy
from book b, bookcopies c, librarybranch l
where b.bookid=c.boid and c.bchid=l.branchid;
3. Delete a book in BOOK table. Update the contents of other tables to reflect this data manipulation
operation (Execute this query at last)
Schema Diagram
Entity-Relationship Diagram
Creation of Tables
select grade,count(customer_id)
from customer
group by grade
having grade>(select avg(grade)
from customer
where city='Banglore');
2. Find the name and numbers of all salesmen who had more than one customer.
select salesman_id,name
from salesman
where salesman_id IN
(select salesman_id
from customer
group by salesman_id
having count(*)>1);
3. List all salesmen and indicate those who have and don’t have customers in their cities (Use UNION
operation.)
select s.salesman_id,s.name,c.cust_name,c.city
from salesman s,customer c
where s.city=c.city
UNION
select s.salesman_id,s.name,'no match',c.city
from salesman s,customer c
where s.city<>c.city and s.salesman_id=c.salesman_id;
4. Create a view that finds the salesman who has the customer with the highest
order of a day.
create view highestorder AS
select s.salesman_id, s.name, o1.ord_no from salesman s, orders o1
where s.salesman_id=o1.salesman_id
and o1.purchase_amt =(
select max( purchase_amt)
from orders o2
where o2.ord_date=o1.ord_date);
5. Demonstrate the DELETE operation by removing salesman with id 1000. All his orders must also be
deleted.
2. Find the movie names where one or more actors acted in two or more movies.
3. List all actors who acted in a movie before 2000 and also in a movie after 2015 (use JOIN
operation).
4. Find the title of movies and number of stars for each movie that has at least one rating and
find the highest number of stars that movie received. Sort the result by movie title.
5. Update rating of all movies directed by ‘Steven Spielberg’ to 5.
Schema Diagram
E-R Diagram
Table Creation
select mov_title
from movies
where dir_id IN (
select dir_id from director
where dir_name = 'Hitchcock' );
2. Find the movie names where one or more actors acted in two or more movies.
select mov_title
from movies m, movie_cast mv
where m.mov_id=mv.mov_id and act_id IN (
select act_id
from movie_cast
group by act_id
having count(act_id)>1)
group by mov_title having count (*)>1;
3. List all actors who acted in a movie before 2000 and also in a movie after 2015 (use JOIN operation).
4. Find the title of movies and number of stars for each movie that has at least one rating and find the
highest number of stars that movie received. Sort the result by movie title.
select m.mov_title,r.rev_stars
from movies m,rating r
where m.mov_id=r.mov_id and r.rev_stars>0
order by m.mov_title;
5. Update rating of all movies directed by ‘Steven Spielberg’ to 5