当前位置: 代码迷 >> Sql Server >> sql语句,取历史表上最新的价格和日期
  详细解决方案

sql语句,取历史表上最新的价格和日期

热度:48   发布时间:2016-04-27 20:22:19.0
求一个sql语句,取历史表上最新的价格和日期
求一条sql语句  
有三个字段,名称,价格,   日期  
 
a   1.2   07-6-12  
a   1.1   07-6-11
b   3.5   07-6-10

如何取到最新的价格和所在的日期     ,如
a   1.2   07-6-12
b   3.5   07-6-10    

谢谢!

------解决方案--------------------
select * from tablename a where 日期=(select top 1 日期 from tablename where 名称=a.名称 order by 日期 desc)
------解决方案--------------------
楼上正解
------解决方案--------------------
select * from 表 a ,(select 名称,max(日期) as 日期 from 表 group by 名称 ) b where a.名称=b.名称 and a.日期=b.日期
  相关解决方案