0% found this document useful (0 votes)
2 views

WEEK 5 (DATA AND WEB DEVELOPMENT)

The document contains a series of SQL queries related to employee and department data management. It includes commands for selecting employee IDs based on salary comparisons, joining tables to extract names and locations, and aggregating salaries by department. The queries demonstrate various SQL functionalities such as subqueries, joins, and groupings to analyze employee data effectively.

Uploaded by

paudelsachida
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

WEEK 5 (DATA AND WEB DEVELOPMENT)

The document contains a series of SQL queries related to employee and department data management. It includes commands for selecting employee IDs based on salary comparisons, joining tables to extract names and locations, and aggregating salaries by department. The queries demonstrate various SQL functionalities such as subqueries, joins, and groupings to analyze employee data effectively.

Uploaded by

paudelsachida
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

WEEK 5 (DATA AND WEB DEVELOPMENT)

1. SELECT employee_id FROM employees WHERE salary > (SELECT AVG(salary) FROM
employees);

2. SELECT department_id FROM departments WHERE department_id IN (SELECT


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

3. SELECT employee_id FROM employees WHERE salary > (select MAX(salary) from
employees GROUP BY department_id HAVING department_id = 50);

4. SELECT e.job_id FROM employees e WHERE e.salary > (FROM employees e2 WHERE
e2.department_id = e.department_id);

5. SELECT e.first_name, e.last_name FROM employees e JOIN departments d ON


e.department_id = d.department_id JOIN locations l ON d.location_id = l.location_id
WHERE l.city = 'Seattle';

6. SELECT d.department_name FROM employees e join departments d on e.department_id


= d.department_id WHERE e.salary = (SELECT MIN(salary
) FROM employees);

7. SELECT employee_id, first_name, hire_date FROM employees WHERE hire_date <


(SELECT MIN(hire_date) FROM employees WHERE department_id = 60);

8.

9. SELECT employee_id, first_name, last_name, job_id FROM employees WHERE job_id =


(SELECT job_id FROM employees WHERE employee_id = 101);

10. SELECT department_id, department_name FROM departments WHERE department_id NOT


IN (SELECT DISTINCT department_id FROM employees);

11. SELECT e.employee_id, e.first_name, e.last_name, e.salary, e.department_id FROM


employees e WHERE e.salary < (SELECT AVG(e2.salary) FROM employees e2 WHERE
e2.department_id = e.department_id);

12. SELECT DISTINCT e.job_id FROM employees e JOIN departments d ON e.department_id


d.department_id JOIN locations l ON d.location_id = l.location_id WHERE
l.location_id (SELECT d2.location_id FROM employees e2 JOIN departments d2 ON
e2.department_id = d2.department_id WHERE e2.employee_id = 200);

13. SELECT d.department_id, d.department_name, SUM(e.salary) AS total_salary FROM


departments d JOIN employees e ON d.department_id = e.department_id GROUP BY
d.department_id, d.department_name HAVING SUM(e.salary) > (SELECT SUM(e2.salary)
FROM employees e2 WHERE e2.department_id = 90);

14. Select employee_id, first_name from employees where salary > (select
employee_id from employees where first_name = 'king');

15. SELECT e.first_name, e.last_name FROM employees e WHERE e.department_id =


(SELECT department_id FROM (SELECT department_id, COUNT(*) AS num_employees FROM
employees
GROUP BY department_id ORDER BY num_employees DESC) WHERE ROWNUM = 1);

You might also like