MYSQL query data sort data and grouped data
In the process of mysql query, data can be filtered, sorted and grouped. Examples of sorted data and grouped data are described below. 1. The data is sorted using ORDER BY select * from where id=10 order by id (positive order, inverted order) positive ASC reverse order DESC from small to small 2, and the grouped data GROUP BY HAVING GROUP BY clause groups a set of rows into summary row records of a small group by the value of a column or expression. The GROUP BY clause returns a row for each packet. In other words, it reduces the number of rows in the result set.
The GROUP BY clause is often used with aggregate functions, such as SUM,AVG,MAX,MIN and COUNT. Aggregate functions are used in the SELECT clause to calculate information about each group.
HAVING can query (filter) which orders have total sales greater than 55000 by using the having clause, as follows:
SELECT
Ordernumber
SUM (quantityOrdered) AS itemsCount
SUM (priceeach*quantityOrdered) AS total
FROM
Orderdetails
GROUP BY ordernumber
HAVING total > 55000
Article from (www.dc3688.com)