工作中遇到这样一个问题,有如下表
id name age
1 tom 20
2 tom 25
3 mary 20
4 mary 27
要查出相同名字中 年龄最大的记录 类似group by name 并 max(age)
group by 好像挺难作到
但这样可以作到
select * from tableName t where age=(select max(age) from tableName b where b.name =t.name )