0% found this document useful (0 votes)
33 views2 pages

311-Lab2 by Long, Nguyen

The document contains the output of multiple SQL queries run against an employee database. It returns statistics like average salary by department, jobs with many employees, total salaries by job, managers with many direct reports, and earliest/latest hire dates by department.

Uploaded by

Long Nguyen
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)
33 views2 pages

311-Lab2 by Long, Nguyen

The document contains the output of multiple SQL queries run against an employee database. It returns statistics like average salary by department, jobs with many employees, total salaries by job, managers with many direct reports, and earliest/latest hire dates by department.

Uploaded by

Long Nguyen
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/ 2

SELECT department_id, MAX(salary) AS "High", MIN(salary) AS "Low",

ROUND(AVG(salary),0) AS "Avg" FROM employee GROUP BY department_id ORDER BY "Avg"


DESC;

DEPARTMENT_ID High Low Avg


------------- ---------- ---------- ----------
90 24000 17000 19333
110 12000 8300 10150
80 11000 8600 10033
20 13000 6000 9500
7000 7000 7000
60 9000 4200 6400
10 4400 4400 4400
50 5800 2500 3500

8 rows selected.

SELECT department_id AS "Dept#", job_id AS "Job", count(job_id) AS "HowMany" FROM


employee GROUP BY job_id, department_id HAVING (count(job_id) > 1) ORDER BY
"HowMany" DESC;

Dept# Job HowMany


---------- ---------- ----------
50 ST_CLERK 4
60 IT_PROG 3
90 AD_VP 2
80 SA_REP 2

SELECT job_id, SUM(salary) AS "totalSalary" FROM employee WHERE salary > 15000 AND
job_id IN('AD_PRES','AD_VP') GROUP BY job_id ORDER BY "totalSalary" DESC;

JOB_ID totalSalary
---------- -----------
AD_VP 34000
AD_PRES 24000

SELECT manager_id, COUNT(employee_id) AS "numOfEmployees" FROM employee WHERE


manager_id NOT IN (100, 101, 102) GROUP BY manager_id,department_id HAVING
(count(employee_id) > 2) ORDER BY "numOfEmployees";

MANAGER_ID numOfEmployees
---------- --------------
124 4

SELECT department_id, MIN(hire_date) AS "earliestHireDate", MAX(hire_date) AS


"latestHireDate" FROM employee WHERE department_id NOT IN (10, 20) GROUP BY
department_id HAVING MAX(hire_date) < to_date('01-01-2000', 'DD-MM-YYYY') ORDER BY
MAX(hire_date) DESC;

DEPARTMENT_ID earliest latestHi


------------- -------- --------
50 95-10-17 99-11-16
60 90-01-03 99-02-07
110 94-06-07 94-06-07
90 87-06-17 93-01-13

SELECT d.department_name, l.city, COUNT(e.employee_id) AS "numOfEmployee" FROM


department d, location l, employee e WHERE d.department_name NOT LIKE 'S%' AND
e.department_id = d.department_id AND l.location_id=d.location_id GROUP BY l.city,
d.department_name HAVING(COUNT(e.employee_id) >= 3) ORDER BY d.department_name ASC;

DEPARTMENT_NAME CITY numOfEmployee


------------------------------ ------------------------------ -------------
Executive Seattle 3
IT Southlake 3

SELECT department_name, city, COUNT(employee_id) AS "numOfEmployee" FROM department


LEFT JOIN employee USING(department_id) LEFT JOIN location USING (location_id)
WHERE department_name NOT LIKE 'A%' GROUP BY city, department_name
HAVING(COUNT(employee_id) < 3) ORDER BY department_name ASC;

DEPARTMENT_NAME CITY numOfEmployee


------------------------------ ------------------------------ -------------
Contracting Seattle 0
Marketing Toronto 2

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy