select
    t.*
from
    表 t
where
    t.price = (select top 1 id from 表 where aid = t.aid order by price)

解决方案 »

  1.   

    --执行查询
    create table #T(id int,Aid int,price int,cid char(1))
    insert into #T select 1,1,5 ,'a'
    insert into #T select 2,1,5 ,'b'
    insert into #T select 3,1,20,'d'
    insert into #T select 4,2,38,'c'
    insert into #T select 5,2,36,'a'
    insert into #T select 6,2,36,'e'--执行查询
    select
        t.*
    from
        #T t
    where
        t.id = (select top 1 id from #T where aid = t.aid order by price,id)
    --输出结果
    id   Aid   price   cid
    1    1     5       a
    5    2     36      a