LIMIT
SELECT column1 FROM table_name LIMIT number_of_rows;
GROUP BY
SELECT column1, COUNT(column2) FROM table_name GROUP BY column1;
AGGREGATE FUNCTIONS
ALIAS
SELECT column_name AS alias_name FROM table_name;
1. COUNT: Count the total number of employees.
sql
SELECT COUNT(*) AS total_employees FROM employees;
2. SUM: Calculate the total salary of all employees.
sql
SELECT SUM(salary) AS total_salary FROM employees;
3. AVG: Find the average salary of employees.
SELECT AVG(salary) AS average_salary FROM employees;
4. MAX: Find the highest salary among employees.
sql
SELECT MAX(salary) AS highest_salary FROM employees;
5. MIN: Find the lowest salary among employees.
SELECT MIN(salary) AS lowest_salary FROM employees;
6. Aggregate with GROUP BY: Calculate the total salary for each department.
SELECT department, SUM(salary) AS total_salary
FROM employees
GROUP BY department;
7. HAVING Clause with Aggregates: Show departments with total salaries above
100,000.
sql
SELECT department, SUM(salary) AS total_salary
FROM employees
GROUP BY department
HAVING total_salary > 100000;
8. COUNT Distinct: Count the number of unique departments.
sql
SELECT COUNT(DISTINCT department) AS unique_departments FROM employees;