0% found this document useful (0 votes)
18 views3 pages

SQL Assignment

12
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
Download as txt, pdf, or txt
0% found this document useful (0 votes)
18 views3 pages

SQL Assignment

12
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1/ 3

------------------SQL

Assignment---------------------------

use SQL_Assignment

select * from EmployeeTitle;


-----------------------------------------------------------------------------------
---

-----------------------------------------------------------------------------------
----------------------------------------------------------------------
------------------Tasks To Be Performed:

-- 1) Display the �FIRST_NAME� from Employee table using the alias name as
Employee_name.

select First_name as Employee_name from Employee;

-- 2) Display �LAST_NAME� from Employee table in upper case.

select upper(Last_name) as LAST_NAME from Employee;

-- 3) Display unique values of DEPARTMENT from EMPLOYEE table.

select distinct Department from Employee;

-- 4) Display the first three characters of LAST_NAME from EMPLOYEE table.

select substring(Last_name,1,3) from Employee;

-- 5) Display the unique values of DEPARTMENT from EMPLOYEE table and prints its
length.

select distinct Department, len(Department) as Length from Employee;

-- 6) Display the FIRST_NAME and LAST_NAME from EMPLOYEE table into a single
column AS FULL_NAME. a space char should separate them.

select concat(First_name,' ', Last_name) as FULL_NAME from Employee;

-- 7) DISPLAY all EMPLOYEE details from the employee table order by FIRST_NAME
Ascending.

select * from Employee order by First_name asc;

-- 8) Display all EMPLOYEE details order by FIRST_NAME Ascending and DEPARTMENT


Descending.

select * from Employee order by First_name asc, Department desc;

-- 9) Display details for EMPLOYEE with the first name as �VEENA� and �KARAN�
from EMPLOYEE table.

select * from Employee where First_name in ('Veena','Karan');


-- 10) Display details of EMPLOYEE with DEPARTMENT name as �Admin�.

select * from Employee where Department in ('Admin');


select * from Employee where Department like 'Admin';

-- 11) DISPLAY details of the EMPLOYEES whose FIRST_NAME contains �V�.

select * from Employee where First_name like 'V%';


select * from Employee where First_name like '%V%';

-- 12) DISPLAY details of the EMPLOYEES whose SALARY lies between 100000 and
500000.

select * from Employee where Salary between 100000 and 500000;

-- 13) Display details of the employees who have joined in Feb-2020.

select * from Employee where year(Joining_date)=2020 and month(Joining_date)=02;

-- 14) Display employee names with salaries >= 50000 and <= 100000.

select concat(First_name,' ',Last_name) as Full_Name, Salary from Employee


where Salary between 50000 and 100000;

-- 16) DISPLAY details of the EMPLOYEES who are also Managers.

select * from Employee E


inner join EmployeeTitle ET
on E.Employee_id = ET.Employee_ref_id
and ET.Employee_Title in ('Manager');

select distinct *, ET.Employee_Title from Employee E


inner join EmployeeTitle ET
on E.Employee_id = ET.Employee_ref_id
and ET.Employee_Title like 'Manager';

-- 17) DISPLAY duplicate records having matching data in some fields of a table.

select Employee_Title, Affective_Date, Count(*) as Total_Count from EmployeeTitle


group by Employee_Title, Affective_Date
having COUNT(*)>1;

-- 18) Display only odd rows from a table.

select * from Employee where Employee_id % 2 <> 0;

-- 19) Clone a new table from EMPLOYEE table.

select * into EmployeeClone from Employee;

select * from EmployeeClone;

-- 20) DISPLAY the TOP 2 highest salary from a table.

select Top 2 * from Employee order by salary desc;

-- 21) DISPLAY the list of employees with the same salary.

select distinct E.Employee_id, E.First_name, E.Salary from Employee E, Employee E1


where E.Salary = E1.Salary and E.Employee_id != E1.Employee_id;

-- 22) Display the second highest salary from a table.

select max(Salary) as Salary from Employee


where Salary not in (select max(Salary) from Employee);

-- 23) Display the first 50% records from a table.

select * from Employee


where Employee_id <= (select Count(Employee_id)/2 from Employee);

-- 24) Display the departments that have less than 4 people in it.

select Department, count(Employee_id) as 'Number of Employees' from Employee


group by Department having count(Employee_id) < 4;

-- 25) Display all departments along with the number of people in there.

select Department, count(Department) as 'Number of Employees' from Employee


group by Department;

-- 26) Display the name of employees having the highest salary in each
department.

select E.Department, E.First_name, E.Salary from(select max(Salary) as 'Total


Salary', Department from Employee group by Department) as NewEmp
inner join Employee E on NewEmp.Department = E.Department
and NewEmp.[Total Salary]=E.Salary;

-- 27) Display the names of employees who earn the highest salary.

select First_name, Salary from Employee


where Salary = (select max(Salary) from Employee);

-- 28) Diplay the average salaries for each department

select avg(Salary) as 'Average Salary', Department from Employee group by


Department

-- 29) display the name of the employee who has got maximum bonus

select E.Employee_id, E.First_name, E.Department, E.Salary,


coalesce((select sum(EB.Bonus_Amount) as BonusAmount from EmployeeBonus EB
where EB.Employee_ref_id = E.Employee_Id),0) from Employee E

-- 30) Display the first name and title of all the employees

select E.First_name, ET.Employee_Title, E.Department from Employee E inner join


EmployeeTitle ET on E.Employee_id = ET.Employee_ref_id

You might also like