求助~~~只有一张表,但是不知道怎么查

tb_Price
  Type 种类
  UpdateTime 价格修改时间
  Price 价格




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

  Type | Price | UpdateTime

 

作者: zxp8819   发布时间: 2011-06-12

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

作者: maco_wang   发布时间: 2011-06-12

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

作者: zy112429   发布时间: 2011-06-12

SQL code
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

作者: yyoinge   发布时间: 2011-06-12

SQL code

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


作者: xiaoliaoyun   发布时间: 2011-06-12

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

作者: rucypli   发布时间: 2011-06-12

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

作者: chuanzhang5687   发布时间: 2011-06-12

引用 1 楼 maco_wang 的回复:

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


一楼这个效率最高的了...

作者: wanyakun   发布时间: 2011-06-12