现在位置: 首页 > 最大值
+1°

Mysql按字段分组取最大值记录

2016年01月18日 13:19:55 MySQL  ⁄ 共 410字 评论数 1 ⁄ 被围观 2,778次
要求:获得按 table1_id 分组,并且取得 table2 中 age 最大的记录信息。 方法一: select * from (select * from table2 order by age desc) as a group by a.table1_id 方法二: select a.* from table2 as a where age = (select max(age) from table2 where a.table1_id=table1_id) 方法三: select a.* from table2 as a where not exists (select * from table2 where table1_id=a.table1_id and age>a.age) 方法四: ...
阅读全文