select * from testTable tt
where id=(Select max(id) from testTable where sort=tt.sort)

解决方案 »

  1.   

    select * from TableName tt
    where in_time=(Select max(in_time) from TableName where product_category_id =tt.product_category_id)
      

  2.   

    select t.product_category_id,
    (select top 1 product_id from tablename where product_category_id=t.product_category_id order by in_time desc)
     as product_id,
    (select top 1 product_name from tablename where product_category_id=t.product_category_id order by in_time desc)
     as product_name,
    (select top 1 in_time from tablename where product_category_id=t.product_category_id order by in_time desc) as in_time 
    from (select distinct product_category_id from tablename) as t