Get the App
SLTechnology News&Howtos  ›  Database  › 

MYSQL query data sort data and grouped data

Shulou Source: shulou.com Published: 2022-06-01 07:07:24 10月03日 Update

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)

Tags: Data grouping clauses sorting queries reverse order functions from small to large one line from small examples information can be passed in other words articles results expressions orders processes sales Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Huawei Docker Shulou Tech Info OPPO Reno