Tutorial by Examples

SUM

Sum function sum the value of all the rows in the group. If the group by clause is omitted then sums all the rows. select sum(salary) TotalSalary from employees; TotalSalary2500 select DepartmentId, sum(salary) TotalSalary from employees group by DepartmentId; DepartmentIdTotalSalary12000...
Payments Table CustomerPayment_typeAmountPeterCredit100PeterCredit300JohnCredit1000JohnDebit500 select customer, sum(case when payment_type = 'credit' then amount else 0 end) as credit, sum(case when payment_type = 'debit' then amount else 0 end) as debit from payments group by ...
The aggregate function AVG() returns the average of a given expression, usually numeric values in a column. Assume we have a table containing the yearly calculation of population in cities across the world. The records for New York City look similar to the ones below: EXAMPLE TABLE city_namepopula...
Partial credit to this SO answer. List Concatenation aggregates a column or expression by combining the values into a single string for each group. A string to delimit each value (either blank or a comma when omitted) and the order of the values in the result can be specified. While it is not part ...
You can count the number of rows: SELECT count(*) TotalRows FROM employees; TotalRows4 Or count the employees per department: SELECT DepartmentId, count(*) NumEmployees FROM employees GROUP BY DepartmentId; DepartmentIdNumEmployees1321 You can count over a column/expression with the eff...

Max

Find the maximum value of column: select max(age) from employee; Above example will return largest value for column age of employee table. Syntax: SELECT MAX(column_name) FROM table_name;

Min

Find the smallest value of column: select min(age) from employee; Above example will return smallest value for column age of employee table. Syntax: SELECT MIN(column_name) FROM table_name;

Page 1 of 1