DS Lab # 06
DS Lab # 06
DS Lab # 06
Date of Conduct: ___________ Submission Date: _________ Signature of the Lab Tutor: ____________
ABILITY TO CONDUCT
LAB PERFORMANCE INDICATOR SUBJECT KNOWLEDGE DATA ANALYSIS AND INTERPRETATION
EXPERIMENT
SCORE
Aggregate Functions:
Aggregate functions are built-in SQL functions that operate on groups of rows and return one value
for the entire group.
Types:
• COUNT(): This function returns the number of rows in the table that satisfies the condition
specified in the WHERE condition. If the WHERE condition is not specified, then the
query returns the total number of rows in the table.
• MAX(): This function is used to get the maximum value from a column.
• MIN(): This function is used to get the minimum value from a column.
• AVG(): This function is used to get the average value of a numeric column.
• SUM(): This function is used to get the sum of a numeric column
• ROUND(): This function rounds a number to a specified number of decimal places.
Example:
SELECT AVG(salary), MAX(salary), MIN(salary), SUM(salary)
FROM employees;
1|Page
DEPARTMENT OF TELECOMMUNICATION ENGINEERING
BACHELOR OF SCIENCE IN CYBER SECURITY
MEHRAN UNIVERSITY OF ENGINEERING & TECHNOLOGY, JAMSHORO
DATABASE SYSTEMS
(2nd SEMESTER, 1st Year) LAB EXPERIMENT # 6
Exercise
Consider the following table Order table.
1. From the following table, write a SQL query to calculate total purchase amount of all
orders. Return total purchase amount.
2. From the following table, write a SQL query to calculate the average purchase amount of
all orders. Return average purchase amount.
3. From the following table, write a SQL query that counts the number of unique salesman_id.
Return number of salesman_id.
Note: Use DISTINCT() function to find the unique values.
4. From the following table, write a SQL query to find the maximum purchase amount.
5. From the following table, write a SQL query to find the minimum purchase amount.
2|Page
DEPARTMENT OF TELECOMMUNICATION ENGINEERING
BACHELOR OF SCIENCE IN CYBER SECURITY
MEHRAN UNIVERSITY OF ENGINEERING & TECHNOLOGY, JAMSHORO
DATABASE SYSTEMS
(2nd SEMESTER, 1st Year) LAB EXPERIMENT # 6
6. From the following table, write a SQL query to find the highest grade of the customers in
each city. Return city and maximum grade.
7. From the following table, write a SQL query to multiply grade with salesman_id. Return
the product of grade and salesman_id.
Note: Use (*) asterik to multiply the columns.
8. From the following table, write a SQL query to find the maximum and minimum grade of
Customer_id with its Name and City.
9. From the following table, write a SQL query to display only first 5 customer_id.
Note: Use LIMIT function().
10. Summarize the whole lab in your own words.
3|Page