Download presentation
Presentation is loading. Please wait.
1
SQL AGGREGATE FUNCTIONS
Advanced SQL Week 41 SQL Aggregate functions COUNT MIN MAX SUM AVG
2
SQL AGGREGATE FUNCTIONS
SQL provides serval built-in numeric functions COUNT: The number of rows containing non-null values MIN: The minimum attribute value encountered in a given column MAX: The maximum attribute value encountered in a given column SUM: The sum of all values for a givenColumn AVG: The arithmetic mean (average) for a specified column
3
SQL AGGREGATE FUNCTIONS Examples
If want to know the number of rows in the employee table we can use: SELECT COUNT(*) FROM employee;
4
SQL AGGREGATE FUNCTIONS Examples
SELECT MIN(hours) AS minimumHours, MAX(hours) AS maximumHours, AVG(hours) AS averageHours FROM project WHERE projectID > 7;
5
Exercise Write an SQL query that Lists the number of products?
Write an SQL query that calculates the total price of all products bought before ? Write an SQL query that calculates the average price? write an SQL query that lists all departments with the number of employee in each department?. Write an SQL query that lists the row with highest price?. Write SQL query that lists the row with lowest price?
6
Answers 1. SELECT COUNT(*) FROM product;
2. SELECT SUM( p_price ) AS total_price_before_ FROM product; 3. SELECT AVG( p_price ) FROM product SQL AGGREGATE FUNCTIONS
7
Answers 4. SELECT did, COUNT( eid ) AS numberOfEmploys FROM works_in
GROUP BY did; 5. SELECT p_code, p_descript, MAX( p_price ) AS maximum_price FROM product; 6. SELECT p_code, p_descript, MIN( p_price ) AS minimum_price
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.