0% found this document useful (0 votes)
48 views6 pages

SQL Queries SIR

The document contains SQL queries to retrieve data from Worker and Bonus tables. The queries select, filter, concatenate, replace, substring, upper case, count, group, join, order by, and perform other operations on the table columns. The queries are designed to return worker details based on name, department, salary range, date joined and other criteria.

Uploaded by

Shuvam Mondal
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
48 views6 pages

SQL Queries SIR

The document contains SQL queries to retrieve data from Worker and Bonus tables. The queries select, filter, concatenate, replace, substring, upper case, count, group, join, order by, and perform other operations on the table columns. The queries are designed to return worker details based on name, department, salary range, date joined and other criteria.

Uploaded by

Shuvam Mondal
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 6

-- Write an SQL query to print details for Workers with the first name as “Vipul” or “Satish” from

Worker table.

select *

from Worker

where FIRST_NAME in ('VIPUL',"SATISH");

-- Write an SQL query to print all Worker details from the Worker table order by FIRST_NAME
Ascending and DEPARTMENT Descending.

Select *

from Worker

ORDER BY FIRST_NAME ASC, DEPARTMENT DESC ;

-- Write an SQL query to print all Worker details from the Worker table order by FIRST_NAME
Ascending.

Select *

from Worker

ORDER BY FIRST_NAME ASC;

-- Write an SQL query to print the FIRST_NAME and LAST_NAME from Worker table into a single
column COMPLETE_NAME. A space char should separate them.

select CONCAT(FIRST_NAME,' ',LAST_NAME) As COMPLETE_NAME

from Worker;

-- Write an SQL query to print the FIRST_NAME from Worker table after replacing ‘a’ with ‘A’.

select REPLACE(FIRST_NAME,'a','A')

from Worker;

-- Write an SQL query that fetches the unique values of DEPARTMENT from Worker table and prints
its length.

select DISTINCT(DEPARTMENT), LENGTH(DEPARTMENT)


from Worker;

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

select SUBSTRING(FIRST_NAME,1,3)

from Worker;

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

select Distinct DEPARTMENT

from Worker;

-- Write an SQL query to fetch “FIRST_NAME” from Worker table in upper case.

select UPPER(FIRST_NAME)

From Worker;

-- Write an SQL query to fetch “BONUS_AMOUNT” and "BONUS_DATE" from the Bonus table.

select BONUS_AMOUNT,BONUS_DATE

from Bonus;

-- 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 Worker;

-- Write an SQL query to fetch “LAST_NAME” from Worker table.

select LAST_NAME

from Worker;

select *

from Worker;
-- get the departments where the average salary is greater than the average company salary

Select AVG(SALARY), DEPARTMENT

from Worker

Group by DEPARTMENT

having AVG(SALARY)> (Select avg(SALARY) from Worker);

Select avg(SALARY)

From Worker;

-- get the average salary of workers in each department

Select AVG(SALARY), DEPARTMENT

from Worker

Group by DEPARTMENT;

-- Write an SQL query to fetch the departments that have less than four people in it.

Select Count(DEPARTMENT), DEPARTMENT

from Worker

Group by DEPARTMENT

HAVING Count(DEPARTMENT) <4;

-- Write an SQL query to fetch the no. of workers for each department in the descending order.

Select Count(DEPARTMENT), DEPARTMENT

from Worker

Group by DEPARTMENT

ORDER BY Count(DEPARTMENT) DESC;

-- Write an SQL query to fetch worker names with salaries >= 50000 and <= 100000.

Select FIRST_NAME, SALARY

from Worker

where SALARY IN

(Select SALARY from Worker where SALARY between 50000 and 100000);
-- Write an SQL query to fetch the names of workers who earn the highest salary.

Select FIRST_NAME, SALARY

From Worker

where SALARY = (Select MAX(SALARY) From Worker);

-- Write an SQL query to print details of the Workers who are also Managers.

Select Worker.FIRST_NAME, Worker.LAST_NAME, Title.WORKER_TITLE

from Worker

Join Title on Worker.WORKER_ID = Title.WORKER_REF_ID

Where Title.WORKER_TITLE = 'Manager';

-- Display all employees who obtained a bonus >= 4000

Select Worker.FIRST_NAME, Worker.LAST_NAME, Bonus.BONUS_AMOUNT

FROM Worker

Join Bonus ON Worker.WORKER_ID=Bonus.WORKER_REF_ID

where Bonus.BONUS_AMOUNT>= 4000;

-- Display all the workers and the bonus they got

Select Worker.FIRST_NAME, Worker.LAST_NAME, Bonus.BONUS_AMOUNT

FROM Worker

Join Bonus ON Worker.WORKER_ID=Bonus.WORKER_REF_ID;

-- Write an SQL query to fetch the count of employees working in the department ‘Admin’.

select count(DEPARTMENT)

from Worker

where DEPARTMENT like 'Admin';


-- Write an SQL query to print details of the Workers who have joined in Feb’2014.

select *

from Worker

where month(JOINING_DATE) = 2 and year(JOINING_DATE) = 2014;

-- Write an SQL query to print details of the Workers whose SALARY lies between 100000 and
500000.

select *

from Worker

where SALARY between 100000 and 500000;

-- Write an SQL query to print details of the Workers whose FIRST_NAME ends with ‘h’ and contains
six alphabets.

select *

from Worker

where FIRST_NAME like '_____h';

-- Write an SQL query to print details of the Workers whose FIRST_NAME contains ‘a’.

select*

from Worker

where FIRST_NAME like '%a%';

-- Write an SQL query to print details of Workers with DEPARTMENT name as “Admin”.

select *

from Worker

where DEPARTMENT like 'Admin%';

-- Write an SQL query to print details of workers excluding first names, “Vipul” and “Satish” from
Worker table.

select *
from Worker

where FIRST_NAME NOT IN ('Vipul', 'Satish');

-- Write an SQL query to print details for Workers with the first name as “Vipul” and “Satish” from
Worker table.

select *

from Worker

where FIRST_NAME IN ('Vipul', 'Satish');

-- Write an SQL query to print all Worker details from the Worker table order by FIRST_NAME
Ascending and DEPARTMENT Descending.

select *

from Worker

order by FIRST_NAME ASC , DEPARTMENT DESC;

-- Write an SQL query to print all Worker details from the Worker table order by FIRST_NAME
Ascending.

select *

from Worker

order by FIRST_NAME ASC;

You might also like