下述查询语句该怎么写?
有一张表,用来存储城市的气象信息,结构如下:
表名: table
字段:city 城市名称
value 气象信息
date 气象日期
现在有个问题,就是怎么查出每个城市的最新的气象信息?查询结果应该如下“
------------------------
南京 25度 10月10日
上海 20度 10月10日
天津 22度 10月9日
成都 30度 10月10日
...
------------------------
谢谢
1、select * from table a where a.date = (select max(date) from table b where a.city = b.city)
2、select tbname.* from tbname,(select city,max(date) m_date from tbname group by city) tbname2 where tbname.date = tbname2.m_date
两种写法都可以,但是在数据量较大时,第一种可能会用较长时间。