表的结构可以理解为:
类型      日期           备注
nokia    20090214     aa  
nokia    20090215     bb 
nokia    20090225     cc 
nokia    20090218     dd   
LG       20090225     cc 
MOTO     20090218     dd      表中数据类型有可能重复,时间不重复,时间越靠后表明数据越新
如何查询指定类型的时间最新的一条数据··比如我要查询类型为 nokia的最新记录,sql语句怎么写?多谢各位好心人··

解决方案 »

  1.   

    select * from tab  a where not exists(select 1 from tab where 日期>a.日期) and 类型='nokia'
      

  2.   

    select * from table where date1=(select max(date1) from table where type='你想要的type')
      

  3.   


    select * from table where 日期 in(selcet max(日期) from table group by 类型) and 类型='nokia';不加后面的and可以查询每种类型的最新数据
      

  4.   


    最后应当还要加一个type='你想要的type'吧
    select * from table 
    where date1=(select max(date1) from table where type='你想要的type')
    and type='你想要的type'
      

  5.   

    select top 1 * from table where 类型='nokia' order by 日期 desc
    简单一点,这样就可以了。