select * 
from table a
where not exists(select 1 from talbe where no_good = a.no_good and gno_goods < a.gno_goods)

解决方案 »

  1.   

    写一个简单的测试
    declare @t table(id int,name varchar(18))
    insert @t 
    select 1,'121212' union all
    select 2,'121212' union all
    select 3,'121211'
    select *
    from @t  a
    where  not exists (
    select 1
    from @t where name = a.name and id < a.id) /*id          name               
    ----------- ------------------ 
    1           121212
    3           121211*/
      

  2.   

    declare @t table(gno_goods varchar(20),no_goods varchar(20),col_other varchar(200))
    insert into @t select '20342899','9111222333447','美术高考名师作品临摹挂图--素描头像 0'
    union all select '20342900','9111222333447','美术高考名师作品临摹挂图--人物速写 0'
    union all select '20486140','9111222333447','电脑2005增刊--网络时尚生活一本通(附光盘) 0'
    union all select '20201694','9780803302006','初级韩国语会话(上册)1-3课--磁带 0'
    union all select '20201725','9780803302006','初级韩国语会话(下册)7-9课--磁带 0 0'
    union all select '20202164','9780803302006','初级韩国语会话(下册)10-11课--磁带 0'
    union all select '20159132','9780995000100','新编儿童英语入门(3)磁带(二盘) 0'
    union all select '20159133','9780995000100','新编儿童英语入门(1)磁带 0'--查询
    select * from @t A
    where not exists (select 1 from @t B  where no_goods=A.no_goods and 
    gno_goods<A.gno_goods
    )
    --结果
    /*
    gno_goods            no_goods             col_other                                                                                                                                                                                                
    -------------------- -------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
    20342899             9111222333447        美术高考名师作品临摹挂图--素描头像 0
    20201694             9780803302006        初级韩国语会话(上册)1-3课--磁带 0
    20159132             9780995000100        新编儿童英语入门(3)磁带(二盘) 0(所影响的行数为 3 行)
    */
      

  3.   


    create table t (gno_goods varchar(20),no_goods varchar(20),col_other varchar(200))
    insert into t select '20342899','9111222333447','美术高考名师作品临摹挂图--素描头像0'
    union all select '20342900','9111222333447','美术高考名师作品临摹挂图--人物速写0'
    union all select '20486140','9111222333447','电脑2005增刊--网络时尚生活一本通(附光盘)0'
    union all select '20201694','9780803302006','初级韩国语会话(上册)1-3课--磁带0'
    union all select '20201725','9780803302006','初级韩国语会话(下册)7-9课--磁带00'
    union all select '20202164','9780803302006','初级韩国语会话(下册)10-11课--磁带0'
    union all select '20159132','9780995000100','新编儿童英语入门(3)磁带(二盘)0'
    union all select '20159133','9780995000100','新编儿童英语入门(1)磁带0'select * from tdelete b from t a,t b where a.no_goods=b.no_goods and a.gno_goods<b.gno_goods
      

  4.   

    问题已经得到解决,问题是这样的:有一个表(名为:syb_zdigene),其中有13个字段,前两个字段为gno_goods,no_goods,其中:gno_goods为编号,是主键,no_goods是条码,可能有重复,要实现的结果是:如果no_goods有重复的,则只取其中一条,最后我使用的SQL语句为:
    select * from syb_zdigene where gno_goods in 
    (
    select gno_goods from
    (select min(gno_goods) gno_goods,no_goods from syb_zdigene group by no_goods ) nnn,
    (select no_goods from syb_zdigene group by no_goods having count(gno_goods)>1) mmm
    where nnn.no_goods=mmm.no_goods
    ) order by no_goods