tb_Price
    Type           种类
    UpdateTime     价格修改时间
    Price          价格
要求显示所有种类最新的价格及其修改时间
如:    Type   |   Price   |   UpdateTime    

解决方案 »

  1.   

    select * from tb_Price a where UpdateTime=
    (select max(UpdateTime) from tb_Price where Type=a.Type)
    order by a.Type
      

  2.   

    select * from tb_Price a
     where not exists(select 1 from tb_Price where Type=a.Type 
                              and UpdateTime>a.UpdateTime)
      

  3.   

    select type, 
    max(UpdateTime) as UpdateTime, 
    cast(substring(max(convert(varchar(19), updatetime, 20) + convert(varchar(18), price)), 20, 18) as decimal(18,2)) as price 
    from tb_price group by type
      

  4.   


    SELECT Type, Price, UpdateTime
    FROM (
            SELECT Type, Price, UpdateTime 
                  ,ROW_NUMBER() OVER (PARTITION BY Type ORDER BY UpdateTime DESC) AS Num
            FROM TB) AS Temp
    WHERE Num = 1
      

  5.   

    select *
    from tb tb1
    where not exits (select 1 from tb where tb1.type=type and tb1.UpdateTime < UpdateTime )
      

  6.   

    select * from tb_Price a
     where not exists(select 1 from tb_Price where Type=a.Type 
                              and UpdateTime>a.UpdateTime)
      

  7.   

    select
     *
    from
     tb t
    where
     UpdateTime=(select max(UpdateTime) from tb where type=t.type )