0% found this document useful (0 votes)
21 views2 pages

DBMS - Worksheet 3 - Answers

The document contains SQL commands for creating and populating an Employee table, including various queries to retrieve specific data. It includes sections for selecting employee details, filtering by job roles and salaries, and performing aggregate functions. The queries demonstrate different SQL functionalities such as selection, filtering, and aggregation based on various conditions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views2 pages

DBMS - Worksheet 3 - Answers

The document contains SQL commands for creating and populating an Employee table, including various queries to retrieve specific data. It includes sections for selecting employee details, filtering by job roles and salaries, and performing aggregate functions. The queries demonstrate different SQL functionalities such as selection, filtering, and aggregation based on various conditions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Question 1

create table Employee(


Empno int primary key,
Empname varchar (20),
Job varchar (20),
Dno int,
Salary float);

Question 2

insert into Employee(Empno, Empname, Job, Dno, Salary) values


(100,'Nimal','HR Assistant', 1, 25000),
(101,'Gamini','IT Manager', 2, 80000),
(102, 'Supipi', 'Software Engineer', 2 , 60000),
(110,'Dev','Project Manager', 2, 85000),
(121,'Sahani','Admin Manager', 1, 70000),
(107, 'Dev', 'Software Engineer', 2 , 68000),
(108,'Anuki','Finance Manager', 3, 70000),
(114, 'Supipi', 'Software Engineer', 2 , 42000),
(122,'Janani','Finance Executive', 3, 32000);

Question 3

----------------- SECTION A -------------------


a) select Empname, Dno from Employee;
b) select distinct Job from Employee;
c) select * from Employee where Salary>50000;
d) select * from Employee where Job='Software Engineer';
e) select * from Employee where Empname like 'S%' and Salary>40000;
f) select * from Employee where Empname like '%ni';
g) select * from Employee where Empname like '%an' or Empname like 'an%' or Empname
like '%an%';
h) select * from Employee where Empname like 'S%' and Empname like '%i' and Dno=2;
i) select * from Employee where Empname like '_a%';
j) select * from Employee where Empname like 'A%' or Empname like 'D%' and
Empno<110;
k) select * from Employee where Empname not like 'S%' AND Empname not like 'N%';
l) select * from Employee where (Empname> 'A' and Empname <'G') or Job not like
'%Engineer%';

----------------- SECTION B -------------------


a) select * from Employee where Empno =101 or Empno=102 or Empno=114;
b) select Empname, Dno from Employee where Empno!=105 and Empno!=107 and Empno!
=122;
c) select * from Employee where Salary>40000 and Salary<100000;
d) select * from Employee where Job='Software Engineer' and !(Salary >50000 and
Salary <70000);

----------------- SECTION C -------------------


a) select count(*) as NumberOfEmployees from Employee;
b) select max(Empno) as HighestEMPno from Employee;
c) select max(Salary) as HighestSalary from Employee;
d) select min(Salary) as SmallestSalary from Employee;
e) select avg(Salary) as AverageSalary from Employee;
f) select count(*) as NoofSoftwareEngineers from Employee where Job='Software
Engineer';
g) select count(*) as EmployeeNoinDep2 from Employee where Dno=2;
h) select count(*) as EmployeesSalary from Employee where (Salary>50000 and
Salary<100000);
i) select count(*) as NamesStartDMS from Employee where Empname like 'D%' or
Empname like 'M%' or Empname like 'S%';
j) select max(Salary) as highestManagerSalary from Employee where Job like
'%Manager%';
k) select round(avg(Salary),2) as avgSalaryofSoftENG from Employee where
Job='Software Engineer';
l) select sum(Salary) as TotalSalaryDept3 from Employee where Dno=3;

You might also like