select a.* from auction a,
(select keyword , max(Currentprice) Currentprice from auction group by keyword) b
where a.keyword = b.keywore and a.currentprice = b.currentprice

解决方案 »

  1.   

    select *from auction a where not exists(select 1 from auction b where a.keyword=b.keyword and a.Currentprice<b.Currentprice)
      

  2.   

    if object_id('pubs..auction') is not null
       drop table auction
    gocreate table auction(id int,keyword varchar(10),Currentprice int)
    insert into auction(id,keyword,Currentprice) values(1,     '塑料' ,      1300)
    insert into auction(id,keyword,Currentprice) values(2,     '塑料' ,      1000)
    insert into auction(id,keyword,Currentprice) values(3,     '橡胶' ,      300)
    insert into auction(id,keyword,Currentprice) values(4,     '钢铁' ,      1200)
    insert into auction(id,keyword,Currentprice) values(5,     '钢铁' ,      3000)
    insert into auction(id,keyword,Currentprice) values(6,     '油墨' ,      1200)
    goselect a.* from auction a,
    (select keyword , max(Currentprice) Currentprice from auction group by keyword) b
    where a.keyword = b.keyword and a.currentprice = b.currentprice
    order by a.iddrop table auction
    /*
    id          keyword    Currentprice 
    ----------- ---------- ------------ 
    1           塑料         1300
    3           橡胶         300
    5           钢铁         3000
    6           油墨         1200(所影响的行数为 4 行)
    */