- 写SQL:找出每个城市的最新一条记录(没写出来)
id 城市 人口 信息 创建时间
1 北京 100 info1 时间戳
2 北京 100 info2 时间戳
3 上海 100 info3 时间戳
4 上海 100 info4 时间戳
info表
SQL语句:
select * from info as info1
join (select city ,max(createtime) as createtime from info group by city) as info2
on info1.createtime=info2.createtime and info1.city=info2.city
结果: