1.

Explain the various group functions in SQL.

Answer»

The built-in functions associated with GROUP functions in SQL are

1. COUNT function:
returns the count of records that satisfies the condition for each group of records.
Example:
SELECT department, COUNT(*)FROM employees WHERE salary > 25000 GROUP BY department;

2. MAX function:
returns the maximum values from the column for each group of records.
Example:
SELECT department, MAX(salary) FROM employees GROUP BY department;

3. MIN function:
returns the lowest values from the column for each group of records.
Example:

SELECT department, MIN(salary) FROM employees GROUP BY department;

4. AVG function:
returns the average values from the column for each group of records.
Example:
SELECT AVG(cost) FROM products WHERE category = ‘Clothing’;

5. SUM function:
returns the total values from the column for each group of records.
Example:
SELECT department, SUM(sales)FROM order_details GROUP BY department;

6. DISTINCT function:
returns the once occurrence of many repeated values from the column for each group of records.
Example:

SELECT DISTINCT department from Employees;



Discussion

No Comment Found

Related InterviewSolutions