DBMS LAS
Qi
a) Fetch first name of worker using alias name as E_Name.
2 SELECT FIRST_NANE AS E NAME FROM “e=ployee”
ENANE
Monika
Niharika
Vishal
Amitabh
Vivek
Vipul
Satish
Geetika
b) List the last name of employees in upper case.SELECT UPPER(LAST_RAE) AS LAST_NANE FRot “employee
LAST_NAME
ARORA
VERMA
SINGHAL,
SINGH
BHAT
DIWAN
KUMAR,
(CHAUHAN.
c) Retrieve the first three characters of employees from their first name.
1 select SUBSTRING(First_Name,1,3) from Employee
SUBSTRING(First_Name,1,3)
Mon
Nin
Vis
Ami
viv
Vip
Sat
Gee
d) Retrieve the unique values of the department and display its length.
SELECT OISTINCT DEPARTMENT, LENGTACOEPARTHENT) AS Length FROH “employee”HR
Account
e) List the first name from employees table after replacing ‘a’ with
2 SELECT REPLACE(FIRST_MAME, ‘2°, A") AS New_First_nome FROM employee
New First Name
Monika,
Vishal
f) Display all worker details, use order by in first name asec and department in desc.
2 SELECT * FROM “employee” ORDER BY FIRST NAME ASC, DEPARTMENT DESC
E.ld FIRSTNAME 4 1 LAST.NAME SALARY JOINING DATE DEPARTMENT » 2
4 Amitabh ‘Singh 600000 2044-02-20 09:00:00 Admin
8 Geetika Chauhan 90000 2014-04-11 09:00:00 Admin
Monika ‘ora 100000 2014-02-20 09:00:00 HR
| 2 Nihanka Verma 80000 2014-06-11 02:00:00 Admin
7 Satish Kumar 75000 2014-01-20 09:00:00 Account
6 Vipul Diwan 200000 2014-06-11 09:00:00 Account
3 Vishal ‘Singhal 300000 2014-02-20 09:00:00 HR
5 Vivek hati £00000 2044-06-11 09:00:00 Admin
2) List the details of an employee whose first name ends with ‘h’ and contains six
alphabets.1 SELECT * FROM “employee” WHERE FIRST_MAME LIKE ("Sh") AND LENGTH(FIRST_NAME)=6
E.ld FIRSTNAME LAST.NAME SALARY JOINING DATE DEPARTMENT
7 Satish Kumar 75000 2014-01-20 09:00:00 Account
h) Display the details of employees who have joined in Feb 2014.
1 SELECT * FROM “eaployee” WHERE J0INING_DATE LIKE ('2606-e2%")
E.ld FIRST.NAME LAST.NAME SALARY JOINING DATE DEPARTMENT
1 Monika ‘Arora 100000 2014-02-20 09:00:00 HR
3 Vishal Singhal 300000 2014-02-20 08:00:00 HR
Ld Amitabh Singh 500000, 2014-02-20 08:00:00 Admin
i) Fetch the employees’ names with salaries over and equal to 50000 and less than
equal to 100000.
2 SELECT CONCAT(FERST_NAME,LAST MAME), SALARY FROM “employee” WHERE SALARY BETHEEN S20Ge AN0 100000
CONCAT(FIRST_NAME,LAST_NAME) SALARY.
MonikaArora 100000
NiharikaVerma 80000
Satishkumar 75000
GeetikaChauhan 30000
j) List the no. of employees for each department in desc order.
1 SELECT OEPARTWENT, COUNT(OEPARTHENT) F20K “employee” GROLP BY DEPARTWENT ORDER BY COUNT(DEPARTMENT) DESCDEPARTMENT COUNT(DEPARTMENT) +
‘Admin
HR
Account
ky Print the details of employees who are also managers.
SELECT * FRom employee, Job title WERE enployee.€_xdefob_title.£ Ref_24 AnD ob title.£_ritlew'iaoager'
E.ld FIRST.NAME LAST_MAME SALARY JONMNG DATE DEPARTMENT. E Ref Id, E Tle AFFECTED FROM
1/Menka oa 100000 2016-22009 0000 HR 1 Manager 20160220 00,0000
5 Vek Bhat ‘00000 2014-06-11 0800.00 Adan 5 Manager 2016 06-11 00.0000
|) Fetch the duplicate records having matching data in some fields of a table.
SELECT DEPARTNENT, JODMING_DATE, COLNT(*) FRON employee GROUP BY DEPARTMENT, JODMING DATE HAVING COUNT(*)>2
DEPARTMENT JOINING DATE __ COUNT(*)
‘Admin 2014-06-11 09:00:00 2
HR 2014-02-20 09:00:00 2
m) Fetch intersecting records of two tables.
1 SELECT * FROM Bonus,Job_Title where Bonus.£ Ref_I
Job_Title.£ Ref_Id
E.Ref_ld BONUS AMOUNT BONUS DATE E Ref_ld E Title AFFECTED FROM
1 5000 2016-02-20 00:00:00 1|manager 2016-02-20 00:00.00
1 4500 2016-02-20 00:00:00 1|Manager 2016-02-20 00:00:00
2 3000 2016-06-11 00.0000 2| Executive 2016-06-11 00:00:00
2 3500 2016-06-11 00:00.00 2| Executive 2016-06-11 00:00:00
3 4000 2016-02-20 00:00:00 3]Lead 2016-06-11 00:00:00
rn) Find the nth (say
) highest salary from a table.First_Name Last_Name salary
Geetika Chauhan 90000
0) Find the 4th highest salary without using TOP or limit method.
FirstName LastName salary
Monika Arora 100000
p) List the details of employees with the same salary.
FirstName Salary
Vivek 500000
Amitabh 500000
q) Display the second highest salary from a table.
FirstName LastName salary
Vishal ‘Singhal 300000
r)_ Display all departments along with the number of people in there.1 select Department, COUNT(Departnent) "No. of Peoples” from Employee group by Department
Department _ No. of Peoples
Account 2
Admin 4
HR 2
5) List the name of employees having the highest salary in each department.
occa
Name Department Salary
Vishal Singhal | HR 300000
Amitabh Singh | Admin 500000
Vivek Bhati | Admin 500000
Vipul Diwan | Account 200000
t) Fetch three min salaries from a table
FirstName Last_Name salary 4 1
Satish Kumar 75000,
Niharika Verma 80000
Geetika Chauhan 90000
u) Fetch departments along with the total salaries paid for each of them.
1 select Department,SUM(Salary) “Total Salary" from Employee group by DepartmentDepartment Total Salary
Account 275000
Admin 1170000
HR 400000
v) Fetch the names of employees who earn the highest salary.
sete cnet Fests," * ast ae) ae" Salary een ployee ere Say (Selec MASeIAy) oR Eptoyee
Name Salary
Amitabh Singh} 500000
Vivek Bhati_ | 500000