取某一列最大值的记录

在sql练习网站上看到的这个题目,感觉有点意思,记录一下

  Find the printer models having the highest price. Result set: model, price.

当时想都没想直接

 

 select model,price from Printer order by price desc limit 1;

然后神奇的发现,报错

搜正解,需求可以有多条记录,然后就想呗

  

select model,price from Printer where price =(select max(price)  from Printer);

猜你喜欢

转载自www.cnblogs.com/note-djl/p/12657018.html