0% found this document useful (0 votes)
35 views6 pages

Dbms 8

Uploaded by

saee7390
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views6 pages

Dbms 8

Uploaded by

saee7390
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

DATABASE PRACTICAL NO.

8: EXECUTE QUERIES
USING SELECT COMMAND WITH WHERE, HAVING,
GROUP BY AND ORDE BY CLAUSE.

Practical Related Questions:


create table Emp(empno number(2),empname varchar(15),salary number(7),phno number(1));
Table created.

create table Dept(deptno number(2),empno number(2),deptname varchar(15),location


varchar(15),jobtype varchar(15));
Table created.

insert into Emp values(1,'Shreyas',80000,0000000000)


insert into Emp values(2,'riya',50000,0000000001)
insert into Emp values(3,'Sam',90000,0000000001)
insert into Emp values(4,'Shree',7000,0000000000)

insert into Dept values(10,1,'Comp','F1','HOD')


insert into Dept values(20,2,'civil','F2','HOD')
insert into Dept values(30,3,'Comp','F3','professor')
insert into Dept values(40,4,'Civil','F4','professor')

OUTPUT:

1 row(s) inserted

Q1]
A] select deptno, sum(salary) from Emp e, Dept d where e.empno=d.empno group by
deptno;

DEPTNO SUM(SALARY)
20 57000
10 170000

B] select empno, deptno from Dept group by deptno,empno;

EMPNO DEPTNO
2 20
4 20
1 10
3 10
C) select min(salary) from Emp e, Dept d where e.empno=d.empno group by deptno;

MIN(SALARY)
7000
80000

D]select empno,jobtype from Dept order by deptname

EMPNO JOBTYPE
4 professor
1 HOD
3 professor
2 HOD

Q2]

A]select min(salary) from Emp e, Dept d where e.empno=d.empno group by deptno;

MIN(SALARY)
7000
80000
B]

B] select deptname, sum(salary) from Emp e, Dept d where e.empno=d.empno


group by deptname;

DEPTNAME SUM(SALARY)
Civil 57000
Comp 170000

C] select deptname from Dept where deptname in (select deptname from Dept group
by deptname having count (*) >2)

DEPTNAME
Civil
Civil
Civil

D] select * from Emp order by empname

EMPNO EMPNAME SALARY PHNO


3 Sam 90000 1
4 Shree 7000 0
1 Shreyas 80000 0
2 riya 50000 1
Exercise:
create table Emp(empno number(2),empname varchar(15),salary number(7),phno
number(1));
Table created.

create table Dept(deptno number(2),empno number(2),deptname


varchar(15),location varchar(15),jobtype varchar(15));
Table created.

insert into Emp values(1,'Shreyas',80000,0000000000)


insert into Emp values(2,'riya',50000,0000000001)
insert into Emp values(3,'Sam',90000,0000000001)
insert into Emp values(4,'Shree',7000,0000000000)
insert into Emp values(5,'yash',70000,0000000000)

insert into Dept values(10,1,'Comp','F1','HOD')


insert into Dept values(20,2,'civil','F2','HOD')
insert into Dept values(10,3,'Comp','F3','professor')
insert into Dept values(20,4,'Civil','F4','professor')
insert into Dept values(20,5,'Civil','F4','professor')

OUTPUT:

1 row(s) inserted

A]selectdeptname,

sum(salary) from

Emp e, Dept d

where

e.empno=d.empno

group by

deptname;

DEPTNAME SUM(SALARY)
Civil 197000
Comp 170000

B] select deptname,min(salary) from Emp e, Dept d where e.empno=d.empno group by


deptname;

DEPTNAME MIN(SALARY)
Civil 7000
Comp 80000
C] select deptname, count(emp.empno) from Dept,Emp where Dept.empno=Emp.empno
group by deptname

DEPTNAME COUNT(EMP.EMPNO)
Civil 3
Comp 2

D] select * from Emp order by salary OUTPUT:


EMPNO EMPNAME SALARY PHNO
4 Shree 7000 0
2 riya 50000 1
5 yash 70000 0
1 Shreyas 80000 0
3 Sam 90000 1

E] select * from Emp , Dept where salary>60000

EMPN EMPNAM SALAR PHN DEPTN EMPN DEPTNAM LOCATIO JOBTYP


O E Y O O O E N E
1 Shreyas 80000 0 10 1 Comp GR HOD
3 Sam 90000 1 10 1 Comp GR HOD
5 yash 70000 0 10 1 Comp GR HOD

F] select deptname, count(emp.empno) from Dept,Emp where Dept.empno=Emp.empno


group by deptname

DEPTNAME COUNT(EMP.EMPNO)
Civil 2
Comp 2

G] select count(*) from Emp where salary>45000

COUNT(*)
3

H] select * from Dept,Emp where deptname='Civil' and salary>(select avg(salary)


from Emp)

DEPTN EMPN DEPTNAM LOCATIO JOBTYP EMPN EMPNAM SALAR PHN


O O E N E O E Y O
20 2 Civil F2 HOD 1 Shreyas 80000 0
20 2 Civil F2 HOD 3 Sam 90000 1
20 2 Civil F2 HOD 5 yash 70000 0

You might also like