SQL NEW Assignment
SQL NEW Assignment
--1 Display the �FIRST_NAME� from Employee table using the alias name as
Employee_name.
select First_name from Employee as Employee_name;
--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(len(Department)),Department from Employee group by Department;
--6 Display the FIRST_NAME and LAST_NAME from EMPLOYEE table into a single column
AS FULL_NAME.
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='Veena' union select * from Employee where
First_name='Karan';
--12 DISPLAY details of the EMPLOYEES whose SALARY lies between 100000 and 500000.
select * from Employee where Salary between 100000 and 500000;
--14 Display employee names with salaries >= 50000 and <= 100000.
select concat(First_name,' ',Last_Name) as Full_Name from Employee where Salary
between 50000 and 100000;
--17 DISPLAY duplicate records having matching data in some fields of a table.
select Employee_title,Affective_Date from Employee_Title group by
Employee_title,Affective_Date having count(*)>1;
--24 Display the departments that have less than 4 people in it.
select Department,count(First_name) as cnt from Employee group by Department having
cnt<4;
--25 Display all departments along with the number of people in there.
select Department,count(First_name) as cnt from Employee group by Department;
--26 Display the name of employees having the highest salary in each department.
select concat(First_name,' ',Last_Name) as Full_Name,Department,Salary from
Employee where Salary in(select max(Salary) from Employee group by Department);
--27 Display the names of employees who earn the highest salary.
select concat(First_name,' ',Last_Name) as Full_Name from Employee where Salary
in(select max(Salary) from Employee);
--29 display the name of the employee who has got maximum bonus.
select concat(e1.First_name,' ',e1.Last_Name) as Full_Name,e2.Bonus_Amount from
Employee e1,Employee_Bonus e2 where e1.Employee_id=e2.Employee_ref_id and
Bonus_Amount in (select max(Bonus_Amount) from Employee_Bonus);
--30 Display the first name and title of all the employees
select e1.First_name,e2.Employee_title from Employee e1,Employee_Title e2 where
e1.Employee_id=e2.Employee_ref_id;