Aggregation Functions in SQL are used to perform calculations on a set of values and return a single summary value. They are essential for generating summary reports and insights from large datasets.
COUNT(): Returns the number of rows that match a specified condition.
Example: To count the number of employees in a company:
SELECT COUNT(*) FROM employees;
SUM(): Adds up all the values in a specified column.
Example: To calculate the total sales amount:
SELECT SUM(sales_amount) FROM sales;
AVG(): Calculates the average value of a specified column.
Example: To find the average score of students:
SELECT AVG(score) FROM exam_results;
MIN(): Returns the smallest value in a specified column.
Example: To find the minimum price of products:
SELECT MIN(price) FROM products;
MAX(): Returns the largest value in a specified column.
Example: To find the highest salary in a department:
SELECT MAX(salary) FROM employees WHERE department_id = 10;
Data in SQL can be understood at different levels, which helps in organizing and analyzing it effectively.
customers table, each row contains data for one customer.customer_name would contain the names of all customers.orders table might include all orders made by customers.Understanding these levels helps in structuring SQL queries and data retrieval.