—在sql server 2000中只能用一个临时表来解决,生成一个自增列,先对val取最大或最小,然后再通过自增列来取数据。
    create table tb(name varchar(10),val int,memo varchar(20))
    insert into tb values(‘a’, 2, ‘a2(a的第二个值)’)
    insert into tb values(‘a’, 1, ‘a1—a的第一个值’)
    insert into tb values(‘a’, 1, ‘a1—a的第一个值’)
    insert into tb values(‘a’, 3, ‘a3:a的第三个值’)
    insert into tb values(‘a’, 3, ‘a3:a的第三个值’)
    insert into tb values(‘b’, 1, ‘b1—b的第一个值’)
    insert into tb values(‘b’, 3, ‘b3:b的第三个值’)
    insert into tb values(‘b’, 2, ‘b2b2b2b2’)
    insert into tb values(‘b’, 4, ‘b4b4’)
    insert into tb values(‘b’, 5, ‘b5b5b5b5b5’)
    go
    select , px = identity(int,1,1) into tmp from tb
    select m.name,m.val,m.memo from
    (
    select t.
    from tmp t where val = (select min(val) from tmp where name = t.name)
    ) m where px = (select min(px) from
    (
    select t.* from tmp t where val = (select min(val) from tmp where name = t.name)
    ) n where n.name = m.name)
    drop table tb,tmp

    select id,name,data from haha a where id= (select max(id) from haha b where a.name = b.name)

    select id,name,data from haha a where not exists(select 1 from haha b where a.name = b.name and a.id < b.id)
    select top 10 * from MF_MMYieldPerformance a where not exists(select 1 from MF_MMYieldPerformance b
    where a.innercode = b.innercode and a.TradingDay < b.TradingDay) order by a.TradingDay desc