Practical-1: Q2) Create The Movie Table
Practical-1: Q2) Create The Movie Table
Table created.
Table created.
Q3) Create the Invoice table-
SQL CAMMAND > create table invoice
2 (
3 invno varchar(3) primary key,
4 mvno number(2) references movie(mvno),
5 custid varchar(3) references customer(custid),
6 issuedate date,
7 returndate date
8 );
Table created.
Q4) DISPLAY ALL THE RECORDS OF CUSTOMER TABLE.
SQL CAMMAND > select * from customer;
6 rows selected.
Q7):- FIND THE MOVIES THAT COST MORE THAN 159 AND ALSO
FIND THE NEW COST AS ORIGINAL COST *15?
SQL CAMMAND > Select Price*15 as newprice from movie where price > 159
TITLE NEWPRICE
Wanted 3000
sholey 7500
3idiot 6000
Q8) PRINT THE NAMES AND TYPES OF ALL THE MOVIES EXCEPT
HORROR MOVIES ?
SQL CAMMAND > select title, type from movie where not type='horror';
TITLE TYPE
----------------------------------
wanted action
welcome comedy
sholey action
3idiot comedy
TYPE
----------
action
comedy
horror
Q10) LIST THE MVNO,TITLE,TYPE OF MOVIES WHOSE STARS BEGINS
WITH LETTER ‘A’.
SQL CAMMAND > select mvno,title,type from movie where star like 'a%';
MAX_PRICE MIN_PRINCE
---------------------------------------
500 100
TYPE COUNT(TYPE)
------------------------------------
action 2
comedy 2
horror 1
PRACTICAL-2
9 rows selected.
SQL CAMMAND > select 'Invoice No. Of Customer id. '||custid||' is '||invno||' and Movie No. is. '||mvno
from invoice;
'INVOICENO.OFCUSTOMERID.'||CUSTID||'IS'||INVNO||'ANDMOVIENO.IS.'||MVNO
-------------------------------------------------------------------------------------------------
Invoice No. Of Customer id. c1 is iv1 and Movie No. is. 11
Invoice No. Of Customer id. c2 is iv2 and Movie No. is. 13
Invoice No. Of Customer id. c4 is iv3 and Movie No. is. 13
Invoice No. Of Customer id. c4 is iv4 and Movie No. is. 14
Invoice No. Of Customer id. c5 is iv5 and Movie No. is. 10
Invoice No. Of Customer id. c5 is iv6 and Movie No. is. 12
Invoice No. Of Customer id. c1 is iv7 and Movie No. is. 12
Invoice No. Of Customer id. c2 is iv8 and Movie No. is. 14
Invoice No. Of Customer id. c6 is iv9 and Movie No. is. 10
9 rows selected.
Q15) SELECT THE TITLE, CUSTID, MVNO FORV ALL THE MOVIES
THAT ARE ISSUED.
SQL CAMMAND > select movie.title,invoice.custid,movie.mvno from movie,invoice where
movie.mvno=invoice.mvno ;
FNAME MVNO
--------------- ----------
pradeep 12
vivek 12
Q17) DISPLAY THE MONTH (IN ALPHABETS) IN WHICH CUSTOMER
ARE SUPPOSED TO RETURN THE MOVIES.
SQL CAMMAND > select to_char(returndate,'month') custid from invoice order by to_char
(returndate);
CUSTID
---------
january
september
june
may
december
march
december
february
march
9 rows selected.
PRACTICAL-3
TITLE CUS
---------------------------
3idiot c4
3idiot c2
Q19) FIND THE NAMES OF CUSTOMERS WHO HAVE BEEN ISSUED
MOVIE OF TYPE ‘HORROR’.
SQL CAMMAND > select fname from customer,invoice where mvno=(select mvno from movie where
type='horror') and customer.custid=invoice.custid
FNAME
---------------
vivek
pradeep
Q20). FIND OUT THE TITLE OF THE MOVIE THAT HAVE BEEN
ISSUED TO THE CUSTOMER WHOSE FNAME IS VIVEK.
SQL CAMMAND > select title from customer,invoice,movie where fname='vivek' and
movie.mvno=invoice.mvno and invoice.custid=customer.custid;
TITLE
-------------------------
wanted
help
Q.21) ADDA COLUMN REMARK OF TYPE VARCHAR AND SIZE 25
TO THE INVOICE TABLE.
SQL CAMMAND > select fname from customer where fname like '_a%';
FNAME
---------------
Rajiv
Q.23) FIND OUT THE MOVIE NUMBER WHICH HAS BEEN ISSUED
TO CUSTOMER WHOSE FIRST NAME IS ‘VIVEK’.
SQL CAMMAND > select invoice.mvno from customer,invoice where customer.custid=invoice.custid
and customer.fname=’vivek’;
MVNO
----------
10
12
'THEMOVIETAKENBY'||FNAME||''||LNAME||'IS'||TITLE
-------------------------------------------------------------------------------
the movie taken by swati sinde is 3idiot
the movie taken by avinash maurya is 3idiot
PRACTICAL-4
Table created.
11 ACTUAL_FEES NUMBER(5),
12 ADMDATE DATE,
13 ADMSTATUS CHAR(1) CHECK (ADMSTATUS='A' OR ADMSTATUS='C' OR
ADMSTATUS='P'),
14 FREESHIP CHAR(1) CHECK (FREESHIP='Y' OR FREESHIP='N')
15 );
Table created.
Table created.
Table created.
Q6) DISPLAY ALL THE RECORDS OF CLASSMASTER TABLE.
Table altered.
Q14) LIST ALL STUDENT WHOSE LAST NAME ENDS WITH ‘E’.
SQL CAMMAND > SELECT * FROM STUDMASTER WHERE STUDLNAME LIKE '%E';
PRACTICAL-5
STUDFNAME STUDLNAME
---------- -------------------------------
AVINASH MAURYA
Q18) LIST ALL THE CLASSES HAVING A TOTAL FEES MORE THAN
18000.
CLASSNAME
--------------------
BSCIT
BSCIT
BSCCS
SQL CAMMAND > SELECT COUNT(*) FROM STUDMASTER LEFT OUTER JOIN CLASSMASTER
ON CLASSMASTER.CLASSID=STUDMASTER.CLASSID LEFT OUTER JOIN STUDDETAIL ON
STUDMASTER.REGNO=STUDDETAIL.REGNO WHERE STUDDETAIL.GENDER='F' AND
CLASSMASTER.CLASSNAME='BSCCS';
COUNT(*)
-----------------
1
SUM(CASHPAID)
----------------------------
15000
TOTAL_CANCEL
-------------------------------
1
CLAS SUM(CANCELATION.AMTREFUNDED)
---- -----------------------------------------------------------------
ART
COM 500
CS
IT
Q23) LIST ALL THE STUDENT WHO HAVE BALANCE FEES FOR
CLASS BSCIT.
STUDFNAME
----------
VIVEK
AVINASHBHAGYA
View created.
6 rows selected.
PRACTICAL-6
Q.1 Consider the following schema:Suppliers(sid:integer, sname varchar,address
varchar) Parts(pid:integer, pname:varchar, color:varchar)
Catalog(sid:integer,pid:integer,cost:money) using these table write the select statement
for following queries:
Solution:
1. Find the names of suppliers who supply some red parts
SQL> select sname from suppliers where sid in (select sid from catalog where pid in (select pid from
parts where COLOR='Red'));
Output:
SNAME
--------------------
Tata Group
Reliance Group
2. Find the sids of suppliers who supply some red or green part
SQL> select sname from suppliers where sid in (select sid from catalog where pid in(select pid from
parts where color='Red' or Color='Green'));
Output:
SNAME
--------------------
Tata Group
Reliance Group
Birla Group
3. Find the sids of suppliers who supply some red part or are at 221 packet
street
SQL> select sname from suppliers where sid in (select sid from catalog where pid in (select pid from
parts where color='Red')) or address='Jogeshwari';
Output:
SNAME
--------------------
Tata Group
Reliance Group
4. Finds the sids of suppliers who supply some red part and some green par
SQL> select sid from catalog where pid = Any(select pid from parts where color='Red' or
Color='Green');
Output:
SID
----------
10
10
20
10
30
10
30
10
Output:
SID
----------
10
6. Grant the select delete and update authority on book to user 'Alex'
SQL>grant select,delete,update on scott.Book to Alex;
Output:
Grant Succeeded
7. Grant the select, insert authority with the capability to grant those
privilegs to other users on Book table to user 'Alex'
PRACTICAL-7
1. Get the details of all the books whose price is greater than the average
price of the books
SQL>Select Title,Author,Publisher,price from book where price>(select Avg(price) from book);
Output:
2. Get the name of all distributors who are supplying the book titled
'software Testing' to the bookshop
SQL> select DISTRIBUTOR From distributor where DISTID IN (select DISTID FROM Orders WHERE
TITLE='SOFTWARE ENG.');
Output:
DISTRIBUTOR
--------------------
KRISHNA
3. Get the name of all distributors who give more discount than the average
discount
SQL> Select Distributor from Distributor where Discount>(select Avg(Discount) from Distributor);
Output:
DISTRIBUTOR
--------------------
Nirali
4. Get the details of all the books whose price is greater than the maximum
of the category average.
SQL> select Title,Author,Publisher from book where price > any (select max(Avg(price)) from book
group by category);
Output:
5. Get the names of all distributors who are supplying the books whose
author is 'FROUZAN'
SQL> select Distributor from Distributor where DistID in (Select DistID from orders where Title=(select
Title from book where Author='FROUZAN'));
Output:
DISTRIBUTOR
--------------------
NURALI
6. Display the orders, which were issued in first quarter of current year
SQL> select orderno,orderdate from sales_header where orderdate between '01-jan-2010' and 2 '30-
mar-2010';
Output:
ORDERNO ORDERDATE
--------------------------------------
6 25-FEB-10
7 25-JAN-10
7. Display the order number, order date, customer name and order amount
for orders having minimum value of 500 Rs
Output:
8. Display the order detail where RIN001 soap is sold minimum 200 Rs
Output:
COMPNAME
--------------------
Reliance Group
2. Give the name of the employees living in the same city where their
company is located
SQL> select ename,compid from emp natural join company;
Output:
ENAME COMPID
-------------------- ----------
Pradeep 101
Prathmesh 102
Amar 103
Ashwin 104
SQL> update emp1 set salary=(select A.SALARY+B.SALARY FROM emp1 A,emp1 B where
A.ename='Raj' and B.ename='Radha') where ename='Raj';
Output:
1 row updated
4. Display how many male and female memebers have joined in january 2006
SQL> SELECT COUNT(GENDER) FROM EMP1 WHERE TO_CHAR(JOINDATE,'MON YYYY')='JAN
2006' GROUP BY GENDER;
Output:
COUNT(GENDER)
-----------------------------
1
1
1. Display the details of all books whose price is more than the average price of all
books
SQL> Select bookid,author,publisher,price from book where price > (select Avg(price) from book);
Output:
BOOKID AUTHOR PUBLISHER PRICE
--------------------------------------------------------------------------------------------
2 GROFF TMG 700
3 JULIA BRADLEY TMG 600
2. Display the details of all books written by Groff and supplied by 'TMG'
Output:
BOOKID YEAR PRICE DISTID TITLE
--------------------------------------------------------------------
2 2008 700 11 SQL-II
3. Create a View to show Title,Author,Publisher and Distributor's Name and name this view as
showDetails
SQL> create view showDetails
As
Select Title,Author,Publisher,Distributors.Name from Book,Distributors
where Book.DistId=Distributors.Distid;
View created.