选择年龄最大的所有人? [英] Selecting all people with the max age?

查看:81
本文介绍了选择年龄最大的所有人?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从具有最大确定值的行中获取值(在此示例中,是最老的成员)

I want to get values from a row with the largest certain value (in this example, the oldest member)

Select * from members where age=max(age)

这项工作可以吗?

如果年龄相同的最老成员超过1个,会发生什么?

And what will happen if there is more than 1 oldest members with the same age?

(我不必担心,因为我使用了auto_increment,但我只是感到好奇)

(I don't have to worry about it because I use auto_increment, but I just got curious)

谢谢.

推荐答案

select * 
from members 
where age = (select max(age) as max_age from members);

如果具有相同最大年龄的成员超过1个,您将获得多个结果.要从中只选择一个:

If there are more than 1 member with the same maximum age, you will get multiple results. To select just one from that:

select * 
from members 
where age = (select max(age) as max_age from members);
limit 1

如果您更喜欢任意特定数据而不是随机数据,则可以选择添加order by.

You can optionally add an order by if you favor any particular data over a random one.

这篇关于选择年龄最大的所有人?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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