Maximum number of columns per group in MySQL

WBOY
Release: 2023-08-27 23:13:02
forward
1332 people have browsed it

MySQL 中每组的最大列数

Let us understand how to find the maximum value of each set of columns in MySQL -

SELECT colName1, MAX(colName2) FROM tableName GROUP BY colName1 ORDER BY colName1;
Copy after login

We will now see an example. Suppose we have a table PRODUCT -

+---------+--------+ | Article | Price | +---------+--------+ | 1 | 255.50 | | 1 | 256.05 | | 2 | 90.50 | | 3 | 120.50 | | 3 | 123.10 | | 3 | 122.10 | +---------+--------+
Copy after login

The following is the query to get the maximum number of columns per group-

Query

SELECT Article, MAX(Price) AS MaxPrice FROM Product GROUP BY Article ORDER BY Article;
Copy after login

Output

+--------------+--------------+ | Article | MaxPrice | +--------------+--------------+ | 0001 | 256.05 | | 0002 | 90.50 | | 0003 | 123.10 | +--------------+--------------+
Copy after login

The above is the detailed content of Maximum number of columns per group in MySQL. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!