Database Systems Lab
Lab 02A: SQL Aggregations
Objective
The students should be able to:
1. Understand the use of GROUP BY and ORDER BY clause
2. Understand the use of HAVING clause
3. Use Aggregate functions like SUM, AVG, MIN, MAX, COUNT, DISTINCT
Submission Requirements
Save your script file and upload it to LMS.
HR Database Schema
Fall 2023 page. 1 Ms. Abeera Tariq
Database Systems Lab
SQL Queries
Write and Execute SQL queries for the following information needs. Make use of suitable
column aliases for the new aggregated columns.
1. How many employees are working in department with ID = 50 ?
2. What is the total number of employees belonging to department 80 and have salary greater
than 24000
3. How many employees are receiving a commission?
4. What is average, minimum and maximum salary of employees having JOB_ID ending with
CLERK? Use suitable alias for each new column.
5. How many distinct departments are there in employees table?
6. How many distinct job_ids are there in employees table?
7. Compute average COMMISSION_PCT rounded up to two decimal places
8. Compute average COMMISSION_PCT ignoring NULL values rounded up to two decimal places
9. Compute average COMISSON_PCT considering NULL values truncated upto two decimal
places.
10. Compute AVG_SALARY for each department in employees table rounded up to two decimal
places
11. Compute AVG_SALARY for each JOB_ID in employees table
12. Compute department-wise total salary of all employees sorted by department_id
grouped by job_id
13. What is the minimum average salary paid to a department?
14. Show the top 5 job_titles based on max_salary. Hint: fetch
15. Make corrections in the query given below:
16. Make corrections in the query given below:
17. Display DEPARTMENT_ID, JOB_ID and department-wise job-wise SALARY_TOTAL of all
employees HAVING SALARY_TOTAL > 10,000 sorted by DEPARTMENT_ID
18. What is average job duration in months for each DEPARTMENT_ID (hint: end_date and
start_date is given)
19. What is the maximum job duration in months for each JOB_ID
20. Display the number of locations for each COUNTRY_ID
Fall 2023 page. 2 Ms. Abeera Tariq