群里有人问。。开始以为 max() ,然后分组就可以。。结果试确实不行。。
正确方式如下:
select myid,price,other from test as t
where price=(select max(t1.price)
from test as t1
where t.myid = t1.myid
)
本文介绍了一种在 SQL 中查询每个ID对应最高价格记录的方法。通过子查询的方式找到每个ID的最大价格,并返回包含ID、最大价格以及其他相关信息的结果集。
群里有人问。。开始以为 max() ,然后分组就可以。。结果试确实不行。。
正确方式如下:
select myid,price,other from test as t
where price=(select max(t1.price)
from test as t1
where t.myid = t1.myid
)
5751