SELECT colName1, MAX(colName2)
FROM tableName
GROUP BY colName1
ORDER BY colName1;
我们现在将看到一个实例。假设我们有一个表 PRODUCT -
+---------+--------+
| Article | Price |
+---------+--------+
| 1 | 255.50 |
| 1 | 256.05 |
| 2 | 90.50 |
| 3 | 120.50 |
| 3 | 123.10 |
| 3 | 122.10 |
+---------+--------+
登录后复制
以下是获取每组最大列数的查询 -
查询
SELECT Article, MAX(Price) AS MaxPrice
FROM Product
GROUP BY Article
ORDER BY Article;
登录后复制
输出
+--------------+--------------+
| Article | MaxPrice |
+--------------+--------------+
| 0001 | 256.05 |
| 0002 | 90.50 |
| 0003 | 123.10 |
+--------------+--------------+
登录后复制
以上就是MySQL 中每组的最大列数的详细内容,更多请关注每日运维网(www.mryunwei.com)其它相关文章!