explain various grogroup function in SQL Related: Chapter Notes - Cha...
GROUP BY:The GROUP BY clause is used in SQL to group rows based on one or more columns. It is often used in conjunction with aggregate functions to perform calculations on groups of data.
Syntax:SELECT column1, column2, ..., aggregate_function(column)
FROM table
WHERE conditions
GROUP BY column1, column2, ...;
HAVING:The HAVING clause is used in SQL to filter groups of data based on a specified condition. It is similar to the WHERE clause, but operates on grouped rows rather than individual rows.
Syntax:SELECT column1, column2, ..., aggregate_function(column)
FROM table
WHERE conditions
GROUP BY column1, column2, ...
HAVING condition;
AVG:The AVG function is used in SQL to calculate the average value of a specified column or expression. It is often used in conjunction with the GROUP BY clause to calculate average values for groups of data.
Syntax:SELECT AVG(column)
FROM table
WHERE conditions
GROUP BY column;
SUM:The SUM function is used in SQL to calculate the sum of a specified column or expression. It is often used in conjunction with the GROUP BY clause to calculate sums for groups of data.
Syntax:SELECT SUM(column)
FROM table
WHERE conditions
GROUP BY column;
MIN:The MIN function is used in SQL to find the minimum value of a specified column or expression. It is often used in conjunction with the GROUP BY clause to find the minimum values for groups of data.
Syntax:SELECT MIN(column)
FROM table
WHERE conditions
GROUP BY column;
MAX:The MAX function is used in SQL to find the maximum value of a specified column or expression. It is often used in conjunction with the GROUP BY clause to find the maximum values for groups of data.
Syntax:SELECT MAX(column)
FROM table
WHERE conditions
GROUP BY column;
COUNT:The COUNT function is used in SQL to count the number of rows in a specified column or expression. It can also be used with the GROUP BY clause to count the number of rows for groups of data.
Syntax:SELECT COUNT(column)
FROM table
WHERE conditions
GROUP BY column;
Examples:1. SELECT department, AVG(salary) FROM employees GROUP BY department;
2. SELECT category, SUM(quantity) FROM products GROUP BY category;
3. SELECT city, MIN(population) FROM cities GROUP BY city HAVING MIN(population) > 100000;