如何获取列中具有最大值的行? [英] How to get a row that has the maximum value in a column?

查看:59
本文介绍了如何获取列中具有最大值的行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取列中具有最大值的行?

How to get a row that has the maximum value in a column?

下面这对我有用,但我不知道是否有另一种更清洁的方法..

This below works for me but I don't know if there is another cleaner way..

SELECT * FROM `moto` where (matricula = (SELECT max(matricula) FROM `moto`)) 

推荐答案

不,这是要走的路.请注意,如果有多个

Nope, this is the way to go. Mind you, this will get you all the rows with that max, if there are multiple

(这个查询也出现在我的一本 MySQL 书中(o'reilly).这是一个典型的例子)

(This query is also featured in one of my MySQL book (o'reilly). It's sort of a classic example)

这篇关于如何获取列中具有最大值的行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆