[英]Get all fields of row with highest value
我用一个users
表学习postgresql。 我尝试通过搜索查询来获取最老的用户,该查询还返回他的姓名,ID和城市 :
我这样开始:
db/us=# SELECT MIN(birthday) FROM users
但这给了我像预期的那样最大的用户生日: 1899-10-18
我还如何获得名字,身份证和城市? 谢谢
如果要保持任何联系,可以加入内联视图:
select u.name, u.id, u.city, u.birthday
from users u
join (select min(birthday) as min_birthday from users) v
on u.birthday = v.min_birthday
或者,您可以在WHERE子句中使用子查询:
select name, id, city
from users
where birthday = (select min(birthday) from users)
如果您不关心保持联系,可以使用LIMIT:
select name, id, city, birthday
from users
order by birthday
limit 1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.