您好,欢迎访问一九零五行业门户网

MySQL 中保存某一列的分组最大值的行

让我们了解如何在 mysql 中查找保存特定列的分组最大值的行 -
查找保存分组最大值的行的语法mysql 中特定列的最大值如下 -
select colname1, colname2, colname3from tablename s1where colname3=(select max(s2. colname3)from tablename s2where s1. colname1= s2. colname1)order by colname1;
假设我们有以下产品表 -
+---------+----------+--------+| article | warehouse| price |+---------+----------+--------+| 1 | north | 255.50 || 1 | north | 256.05 || 2 | south | 90.50 || 3 | east | 120.50 || 3 | east | 123.10 || 3 | east | 122.10 |+---------+----------+--------|
以下是查询 −
查询select article, warehouse, pricefrom product p1where price=(select max(p2. price)from product p2where p1. article= p2. article)order by article;
输出+-------------+----------------+------------+| article | warehouse | price |+-------------+----------------+------------+| 0001 | north | 256.05 || 0002 | south | 90.50 || 0003 | east | 123.10 |+-------------+----------------+------------+
上面的查询使用了相关子查询。
以上就是mysql 中保存某一列的分组最大值的行的详细内容。
其它类似信息

推荐信息