Tutorial by Examples

SELECT product, SUM(quantity) AS "Total quantity" FROM order_details GROUP BY product;
Assume a table of employees in which each row is an employee who has a name, a department, and a salary. SELECT department, MIN(salary) AS "Lowest salary" FROM employees GROUP BY department; This would tell you which department contains the employee with the lowest salary, and what t...
SELECT department, COUNT(*) AS "Man_Power" FROM employees GROUP BY department;
SELECT department, COUNT(*) AS "Man_Power" FROM employees GROUP BY department HAVING COUNT(*) >= 10; Using GROUP BY ... HAVING to filter aggregate records is analogous to using SELECT ... WHERE to filter individual records. You could also say HAVING Man_Power >= 10 since HAVIN...
Group Concat is used in MySQL to get concatenated values of expressions with more than one result per column. Meaning, there are many rows to be selected back for one column such as Name(1):Score(*) NameScoreAdamA+AdamA-AdamBAdamC+BillD-JohnA- SELECT Name, GROUP_CONCAT(Score ORDER BY Score desc SE...
Table ORDERS +---------+------------+----------+-------+--------+ | orderid | customerid | customer | total | items | +---------+------------+----------+-------+--------+ | 1 | 1 | Bob | 1300 | 10 | | 2 | 3 | Fred | 500 | 2 | | 3 | ...

Page 1 of 1