SQL ASSIGNMENTS

#snehalsheth

snehal sheth Jul 07 2021 · 1 min read
Share this

ASSIGNMENT-1

Q-1. Write an SQL query to fetch “FIRST_NAME” from Worker table using the alias name as <WORKER_NAME>.

SELECT FIRST_NAME AS WORKER_NAME FROM WORKERS;

Q-2. Write an SQL query to fetch unique values of DEPARTMENT from Worker table.

SELECT DISTINCT  DEPARTMENT FROM WORKERS;

Q-3. Write an SQL query to show the last 5 record from a table.

SELECT * FROM WORKERS

WHERE

WORKER_ID > (SELECT COUNT(*) FROM WORKERS)-5 ;

ASSIGNMENT-2

Q-1. Write an SQL query to print the first three characters of  FIRST_NAME from Worker table.

SELECTSUBSTRING(FIRST_NAME,1,3)FROM WORKERS;

 Q-2. Write an SQL query to find the position of the alphabet (‘a’) in the first name column ‘Amitabh’ from Worker table.

Select CHARINDEX('a', 'Amitabh') as Position;

Q-3. Write an SQL query to print the name of employees having the highest salary in each department.

SELECT t.DEPARTMENT,t.FIRST_NAME,t.Salary from(SELECT max(Salary) as TotalSalary,

              DEPARTMENT from WORKERS group by DEPARTMENT) as TempNew

Inner Join WORKERS t on TempNew.DEPARTMENT=t.DEPARTMENT

 and TempNew.TotalSalary=t.Salary;

Comments
Read next