Aggregate Functions
SUM – Return summation of selected column – Aggregate Functions
SUM function returns the summation of selected column. You can also obtain the sum excluding duplicate data using DISTINCT parameter, however, you rarely use DISTINCT parameter with SUM. example: Return the summation of employees’ age. SELECT SUM(age) FROM tbEmpTable; SUM(age) ————————– 123 example: Return the summation of employees’ age after excluding duplicate ages. SELECT SUM(DISTINCT [...]
Posted in: Aggregate Functions | Comments Off
STDDEV, STDEV – Return standard deviation of selected column – Aggregate Functions
STDDEV or STDEV function return the standard deviation of selected column. Standard deviation tells how much dispersion there is from an average value. Small standard deviation tells the each value is close to the average value. Large standard deviation indicates that the each value is spread out from average value. example: Return the standard deviation [...]
Posted in: Aggregate Functions | Comments Off
MIN – Return minimum value of selected column – Aggregate Functions
MIN function returns the minimum value of selected column. The value can be number, character, or datetime. example: Return the smallest salary of employees. SELECT MIN(salary) FROM tbEmpTable; MIN(salary) ————————— 120000 example: Return the smallest salary in each department. SELECT deptCD, MIN(salary) FROM tbEmpTable GROUP BY deptCD; deptCD, MIN(salary) —————————- 100 120000 200 156000 300 [...]
Posted in: Aggregate Functions | Comments Off
MAX – Return largest value of selected column – Aggregate Functions
You can use MAX function to return the largest value of your selected column. The value can be number, character, datetime. example: Return the highest salary of employees. SELECT MAX(salary) FROM tbEmpTable MAX(salary) ——————————– 543000 example: Return the highest salary in each department. SELECT deptCD, MAX(salary) FROM tbEmpTable GROUP BY deptCD; deptCD, MAX(salary) ——————————– 100 [...]
Posted in: Aggregate Functions | Comments Off
COUNT – Count the number of records – Aggregate Functions
COUNT function can count the number of records(rows). If you use DISTINCT, you can eliminate duplicated data and count the number of rows. example: to count the number of employees. SELECT COUNT(*) FROM tbEmpTable; COUNT(*) ———————- 24 example: count the number of employees in each department. SELECT deptCD, COUNT(*) FROM tbEmpTable GROUP BY deptCD; deptCD, [...]
Posted in: Aggregate Functions | Comments Off
AVG – Return avarage number – SQL Aggregate Functions
AVG function returns average number from a specific column. example: to find average value of employees’ salary. SELECT AVG(salary) FROM tbSalaryTable; AVG(salary) —————————————– 254000
Posted in: Aggregate Functions | Comments Off