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

SQL

Uploaded by

ashishchafle007
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

Uploaded by

ashishchafle007
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

>Write a query to find the manager ID and the salary of the lowest-paid employee

for that manager.


SELECT manager_id, MIN(salary)
FROM employees
WHERE manager_id IS NOT NULL
GROUP BY manager_id
ORDER BY MIN(salary) DESC;

>Write a query to get the average salary for each job ID excluding programmer.
SELECT job_id, AVG(salary)
FROM employees
WHERE job_id <> 'IT_PROG'
GROUP BY job_id;

>Write a query to list the number of jobs available in the employees table.
SELECT COUNT(DISTINCT job_id)
FROM employees;

>Write a query to get the job ID and maximum salary of the employees where maximum
salary is greater than or equal to $4000.
SELECT job_id, MAX(salary)
FROM employees
GROUP BY job_id
HAVING MAX(salary) >=4000;

>Write a query to get the average salary and number of employees working the
department 90
SELECT AVG(salary),count(*)
FROM employees
WHERE department_id = 90;

>Write a query to get the number of employees with the same job.
SELECT job_id, COUNT(*)
FROM employees
GROUP BY job_id;

>Write a query to get the difference between the highest and lowest salaries.
SELECT MAX(salary) - MIN(salary) DIFFERENCE
FROM employees;

>Write a query to get the average salary,department_id,count employee for all


departments employing more than 10 employees
SELECT department_id, AVG(salary), COUNT(*)
FROM employees
GROUP BY department_id
HAVING COUNT(*) > 10;

>SELECT department_id, AVG(salary), COUNT(*)


FROM employees
GROUP BY department_id
HAVING COUNT(*) > 10;

>Write a query to get the maximum salary of an employee working as a Programmer.


SELECT MAX(salary) FROM employees WHERE job_id = 'IT_PROG';

>Write a query to find the 4th minimum salary in the employees table
-SELECT DISTINCT salary
FROM employees e1
WHERE 4 = (SELECT COUNT(DISTINCT salary)
FROM employees e2
WHERE e2.salary <= e1.salary);

>Write a query to find the name (first_name, last_name) and the salary of the
employees who have
a higher salary than the employee whose last_name='Bull'
-SELECT FIRST_NAME, LAST_NAME, SALARY
FROM employees
WHERE SALARY >
(SELECT salary FROM employees WHERE last_name = 'Bull');

>write a query to find the name (first_name, last_name), and salary of the
employees who earns more than the average salary and works in any of the IT
departments
-SELECT first_name, last_name, salary
FROM employees
WHERE department_id IN
(SELECT department_id FROM departments WHERE department_name LIKE 'IT%')
AND salary > (SELECT avg(salary) FROM employees);

>Write a query to select last 10 records from a table


SELECT * FROM (SELECT * FROM employees ORDER BY employee_id DESC LIMIT 10) sub
ORDER BY employee_id ASC;

>Write a query to get 3 minimum salaries


-SELECT DISTINCT salary
FROM employees a
WHERE 3 >= (SELECT COUNT(DISTINCT salary)
FROM employees b
WHERE b.salary <= a.salary)
ORDER BY a.salary DESC;

>Write a query to get 3 maximum salaries


-SELECT DISTINCT salary
FROM employees a
WHERE 3 >= (SELECT COUNT(DISTINCT salary)
FROM employees b
WHERE b.salary >= a.salary)
ORDER BY a.salary DESC;

>Write a query to find the name (first_name, last_name) and the salary of the
employees who have a higher salary than the employee whose last_name='Bull'

-SELECT FIRST_NAME, LAST_NAME, SALARY FROM employees WHERE SALARY > (SELECT salary
FROM employees WHERE last_name = 'Bull');

>Write a query to fetch even numbered records from employees table


-SELECT * FROM EMPLOYEE WHERE id IN(SELECT id FROM EMPLOYEE WHERE id%2 = 0);

>Write a query to display the employee ID, first name, last name, and department
names of all employees.
-SELECT employee_id, first_name, last_name,
(SELECT department_name FROM departments d
WHERE e.department_id = d.department_id) department
FROM employees e ORDER BY department;

>Write a query to find the name (first_name, last_name), and salary of the
employees who earn the same salary as the minimum salary for all departments.
-SELECT * FROM employees
WHERE salary = (SELECT MIN(salary) FROM employees);

>Write a query to display the employee ID, first name, last name, salary of all
employees whose salary is above average for their departments
-SELECT employee_id, first_name
FROM employees AS A
WHERE salary >
(SELECT AVG(salary) FROM employees WHERE department_id = A.department_id);

>Write a query to find the name (first_name, last_name) of the employees who are
manager
- SELECT e.first_name, e.last_name FROM employees AS e WHERE e.employee_id IN
(SELECT e.manager_id FROM employees AS e);

You might also like