S.I.E.S College of Commerce and Economics: Laboratory Journal
S.I.E.S College of Commerce and Economics: Laboratory Journal
LABORATORY JOURNAL
B.Sc. (I.T.)
Semester V
2009 – 2010
Name :
Roll No. :
Batch :
Subject :
SIES COLLEGE OF
COMMERCE AND ECONOMICS
SION(EAST), MUMBAI – 400 022.
B.Sc.(I.T.)
Semester V
Certificate
Certificate
Co-ordinator Lecturer-in-charge
Date : Date :
Emp(ename,street,city)
Work(ename,cname,sal)
Company(cname,city)
Manager(ename,mname)
6 rows selected.
CNAME CITY
---------- ----------
sbi furus
sbi mumbai
Chiaro sion
Emirates gotham
Chiaro mumbai
sbi santacruz
ENAME MNAME
---------- ----------
tazz tom
diths tazz
tom heena
harry tom
ENAME
----------
diths
heena
2. Find the name ,street,city of all employees who work at SBI and salary greater than
10000
3.Find all employees in database who live in the same city as the company which they
work.
4 Find all employees in database who live in the same city and same street as their
managers.
ENAME
----------
tazz
tom
dick
6. Find all employees in database who earn more than each employee of SBI.
Ans: SQL>select ename from work27 where sal>all(select sal from work27 where
cname='sbi');
ENAME
----------
tazz
tom
7. Assume company located in several cities. Find all company located in every city in
which SBI is located.
Ans: SQL>select distinct cname from co27 where city in (select city from co27 where
cname='sbi');
CNAME
----------
sbi
Chiaro
8.Find all employees who earn more than average salary of all employees of their
company.
ENAME SAL
---------- ----------
harry 65000
tazz 60000
diths 45000
CNAME
----------
Chiaro
sbi
Emirates
Ans: SQL>select distinct cname from work27 where sal = (select min(sal) from work27);
CNAME
----------
Chiaro
11. Find those companies whose employee earn a higher, on average than average salary
at SBI.
where sal > (select avg(sal) from work27 where cname='sbi' group by cname);
CNAME
----------
sbi
Emirates
Emp(empid,ename,age,sal)
Works(empid,did,pct_time)
Dept(did,budget,mgrid)
Table created.
1 tashu 20 45000
2 priya 21 40000
3 shraddha 20 42000
4 prachi 22 100005
5 amreen 19 80000
Table created.
1 12 78
1 2 67
2 1 56
2 2 77
3 12 44
SQL 2-Journal Page 8
TY BSc IT –Sem V 2009
3 2 32
4 4 4
5 2 99
8 rows selected.
Table created.
1 12000 1
2 100020 5
4 90000 4
12 120000 1
1. Print name and age of each employee who work in both hardware and software
department.
1 tashu 20
2 priya 21
3 shraddha 20
5 amreen 19
6 rows selected.
2. Print name of employee whose budget exceeds of all departments that he or she
works in.
where sal > all (select budget from dept27 , work27q2 where dept27.did=work27q2.did
and work27q2.empid=emp27q2.empid);
ENAME
----------
prachi
MID
----------
ENAME
----------
tashu
MID
----------
SQL 2-Journal Page 10
TY BSc IT –Sem V 2009
Book(id,title,author,publisher,category,year,price,distid)
DISTID
----------
1 pulpy shimla 5
2 mango furus 2
3 orange nagpur 4
1. Display the details of all books whose price is more than the average price of all
books.
DISTID
----------
Q2. Display the details of books written by ‘Agatha’ and supplied by ‘TMH’.
DISTID
----------
Emp(eid,ename,address,phone,salary,design,did,doj_date)
Table created.
DID DNAME
------ ----------
2001 it
2002 sales
2003 hr
PID PNAME
---- ----------
103 hall
ENAME
----------
Subho
from temp10
where salary=(select min(salary) from temp10);
ENAME
----------
Riddhi
COUNT(EID) DID
---------- ----------
1 2001
1 2003
1 2002
3 rows deleted.
COUNT(EID)
----------
2
Table deleted.
Supplier(sno,sname,status,city)
Parts(pno,pname,color,weight)
Shipment(sno,pno,qty,s_date)
2 ,city char(10));
Table created.
11 subh 1 mumbai
12 tasu 2 goa
13 vini 3 kerla
14 tess 4 jammu
11 1 40 01-JAN-09
15 1 20 03-FEB-09
13 3 50 05-MAR-09
14 4 30 31-AUG-09
15 5 60 31-AUG-09
COUNT(DISTINCTSNO)
------------------
PNO
----------
Ans:SQL> select sname from sup1027 where sno not in (select sno from ship27);
SNAME
----------
tasu
5. Create a dupliocate table named sup_dup with all records for supplier table.
Table created.
11 subh 1 mumbai
12 tasu 2 goa
13 vini 3 kerla
14 tess 4 jammu
COUNT(SNO)
----------
Ans:SQL> select distinct city from parts1027 union select distinct city from sup1027;
CITY
----------
dadar
delhi
goa
goa
jammu
jammu
kerla
mumbai
mumbai
pune
pune
11 rows selected.
Ans:SQL> select sname from sup1027 where sname like '%d$_a%' escape '$';
SNAME
----------
duaa
no rows selected
and ship1027.pno=parts1027.pno;
PNAME
----------
wiper
OR
3 and to_char(sdate,'q')=4
4 and ship1027.pno=parts1027.pno;
PNAME
----------
Wiper
Supplier(sno,sname,status,city)
parts(pno,pname,color,weight,city)
11 subh 1 mumbai
12 tasu 2 goa
13 vini 3 kerla
14 tess 4 jammu
15 kini 5 pune
16 duaa 6 dadar
6 rows selected.
99 bldg mumbai
98 railway goa
97 house jammu
96 office dehli
95 socket pune
Table created.
11 1 99 4
12 2 98 5
13 3 97 6
14 4 96 1
11 1 99 4
12 2 98 5
13 3 97 6
14 4 96 1
15 3 99 6
16 4 96 4
6 rows selected.
1. Display parts numbers of the parts that are supplied either by ‘mumbai’ supplier or to a
‘Mumbai ‘ project.
PNO
----------
where sup1027.sno=spj2727.sno
and sno='11';
COUNT(PNO)
----------
3. Add a constraint valid_colors which will check for valid color:red,green and blue.
Table altered.
4. Display the supplier no, partsno pair such that indicated supplier does not supply
indicated part.
5. Display parts no. for parts supplied by more than one supplier.
no rows selected
6. Display supplier name for suppliers who supplies atleast one part.
2 sup1027.sno=spj2727.sno;
SNAME
----------
subh
tasu
vini
tess
7. Define a view consisting of all projects that are supplied by s1 and p1.
3 where pr1027.pr_id=spj2727.pr_id
Student2840(snum,sname,major,level,age)
Class2840(cname,meets_at,room,fid)
Enrolled2840(snum,cname)
Faculty2840(fid,fname,deptid)
Table created.
1 row created.
SQL> /
1 row created.
SQL> /
1 row created.
SQL> /
1 row created.
Table created.
1 row created.
SQL> /
1 row created.
SQL> /
1 row created.
SQL> /
1 row created.
Table created.
SQL 2-Journal Page 28
TY BSc IT –Sem V 2009
1 row created.
SQL> /
1 row created.
SQL> /
1 row created.
SQL> /
1 row created.
Table created.
1 row created.
SQL> /
1 row created.
SQL> /
1 row created.
SQL> /
1 row created.
1. Find the names of all juniors who are enrolled in a class taught by Mr.X.
SNAME
----------
arena
2.Find the names of all classes that either meet in room r1 or have 5 or more students
enrolled
3 union
CNAME
----------
CS
IT
3. Print the level and average age of students for that level, for each level.
from stud39
group by slevel;
SLEVEL AVG(AGE)
------ ----------
Jr 19.5
Sr 21.6666667
4. Print the level and average age of students for that level, for all levels except junior.
from stud39
where slevel<>'Jr'
group by slevel;
SLEVEL AVG(AGE)
------ ----------
Sr 21.6666667
5.Find the names of students who are enrolled in the maximum number of classes.
where snum = (select snum from enrolled2840 group by snum having count(snum)=(select
max(count(snum)) from enrolled2840 group by snum));
SNAME
---------
noorah
6. Find the names of students who are not enrolled in any class.
from stud39
SNAME
----------
Albert
Supplier(sid,sname,address)
Parts(pid,pname,color)
category(sid,pid,cost)
Table created.
10 nuts red
11 cluch blue
12 handle red
13 motor black
Table created.
PNAME
----------
nuts
cluch
handle
motor
SNAME
----------
adman
tess
3. Find sid of suppliers who charge more for same part than average cost of that part.
Ans:
SQL> select a.sid,a.pid from tcat a where cost>(select avg(cost) from tcat b group by
b.pid having b.pid=a.pid);
PID SID
---------- ----------
10 2
10 3
10 4
11 1
11 3
11 4
12 1
12 2
12 4
13 1
13 2
PID SID
---------- ----------
13 3
12 rows selected.
Q9.
dist1027 (did,name,city)
Table created.
Table created.
1 TMG shimla
2 mango furus
3 orange nagpur
1.Display the details of all books whose price more than average price of all books.
from book1027);
where author='Grof'
book1027.did=dist1027.did;
---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------
select title,author,publisher,name
from book1027,dist1027
where book1027.did=dist1027.did;
from book1027
(select max(price)
from book1027
from book1027));
TITLE
----------
Famousfive
Customer(cid,cname,fname,area,phone)
Movie(mvno,mname,title,star,price)
Invoice(invno,mvno,cid,isuued_date,return_date)
Table created.
1 row created.
SQL> /
1 row created.
SQL> /
1 row created.
SQL> /
1 row created.
SQL> /
1 row created.
Table created.
1 row created.
SQL> /
1 row created.
SQL> /
1 row created.
SQL> /
1 row created.
SQL>/
1 row created.
PRICE
--------
300
250
350
PRICE
--------
200
300
Table created.
SQL 2-Journal Page 44
TY BSc IT –Sem V 2009
1 row created.
SQL> /
1 row created.
SQL> /
1 row created.
SQL> /
1 row created.
60 30 5 14-FEB-09 14-MAR-09
63 33 1 09-MAR-09 09-APR-09
64 31 7 04-AUG-09 04-SEP-09
65 32 5 21-JAN-09 21-FEB-09
1. Find the name of movie having ‘a’ in the second position in their name.
select mname
from movie
MNAME
--------------------
Fame
where cid='01';
1 row updated.
60 30 5 14-FEB-09 14-MAR-09
63 33 1 12-MAR-07 09-APR-09
64 31 7 04-AUG-09 04-SEP-09
65 32 5 21-JAN-09 21-FEB-09
select title,count(mvno)
from movie
group by title;
TITLE COUNT(MVNO)
-------------------- -----------
wakeupsid 1
harrypotter 1
kites 2
twilight 1
Table altered.
5. Display the customer names who are having the invoice of movies price 200.
customer.cid=invoice1.cid and
invoice1.mvno=movie.mvno;
CNAME
----------
jerry
empp(eno,ename,dtjoin,city,deptid)
Dept(deptid,dname,manager)
Table created.
21 IT Adam
22 HR Smith
23 Sales John
24 Product Annie
Table created.
Table created.
1.Display the name of the employee who get second highest basic.
SQL> select ename from empp98 e where e.eno=(select eno from sal98 where
basic>all(select basic fro
ENAME
----------
John
Table altered.
SQL> select e.eno,ename,pay from empp98 e,sal98 s,dept890 d where dname='IT' and
e.eno=s.eno and e.deptid=d.deptid;
1 Adam 2575
3 John 2775
5 Julia 275
ENAME DTJOIN
---------- ---------
John 14-MAR-09
Smith 14-MAR-09
Person(driverid,name,address)
Car(licence,model,year)
towns(driverid ,licence )
Table created.
1003 rani vt
Table created.
11 mazde 1993
22 bmw 2007
33 audi 2009
Table created.
Table created.
DRIVERID LICENCE
---------- ----------
1001 11
1002 22
1003 33
Table created.
1. Find total number of people who owned cars that were involved in accident in
1993.
from taccident,tparticipated
to_char(acci_date,'yyyy')=1993;
COUNT(DRIVERID)
---------------
1 row deleted.
3. Update the damage amount for the car with licence number ‘AA101’ in the
accident with report number ‘AR199’ to 3000.
1 row updated.
4. Display the names of the drivers who owns a car with model ‘mazde’ and year
1993.
from tperson,towns,tcar
year=1993;
NAME
----------
karisma