--是不是这样,就是在你的表里面选择只出现一行的行
select col1,col2,...,coln from yourtable group by col1,col2,...,coln having count(*)=1

解决方案 »

  1.   

    那就稍改一下:
    select * from a t  
    where not exists( select * from a where NH<>t.NH 
       and ',,,'+NH+',,,' like '%,,,'+t.NH+',,,%')
    and not exists(select * from a where NH<>t.NH 
       and ',,,'+t.NH +',,,'like '%,,,'+NH+',,,%')
      

  2.   

    SELECT *
    FROM A M
    WHERE NOT EXISTS (
        SELECT TOP 1 1
        FROM A
        WHERE NH <> M.NH
            AND M.NH LIKE '%' + NH + '%'
    )这样不行吗?
      

  3.   

    pbsql(风云)你好 我要的结果就是你描述的那样 :)
      

  4.   

    haoK(haoK.Y)大侠,你的我试过了还是不成!
      

  5.   

    按楼主的意思结果应该是:a12,b,c1,c2 是吗?
      

  6.   

    都不行呀,真有那么难吗?不少高手都试过了,就连zjcxc(邹建)也没有看掉它,奇了怪了,真是奇了怪了 :)
      

  7.   

    select * from a t
     where not exists(select * from a where NH<>t.NH and NH like '%'+rtrim(t.NH)+'%')
       and not exists(select * from a where NH<>t.NH and t.NH like '%'+rtrim(NH)+'%')再试试!
      

  8.   

    不想说了,你自己去运行吧:
    declare @a table(NH varchar(10))
    insert into @a(NH)
    select       'a' union all
    select       'a1' union all
    select       'a12' union all
    select       'b' union all
    select       'c' union all
    select       'c1' union all
    select       'c2'select * from @a t
     where not exists(select * from @a where NH<>t.NH and (NH like '%'+t.NH+'%' or t.NH like '%'+NH+'%'))
      

  9.   

    回复  pbsql(风云):
      
       就是一个字段。
      

  10.   

    create table a (
    nh char(10)
    )insert a
    select
           'a'
    union all select
           'a1'
    union all select
           'a12'
    union all select
           'b'
    union all select
           'c'
    union all select
           'c1'
    union all select
           'c2' select * from a t
     where not exists(select * from a where NH<>t.NH and NH like '%'+rtrim(t.NH)+'%')
       and not exists(select * from a where NH<>t.NH and t.NH like '%'+rtrim(NH)+'%')--结果
    /*
    nh         
    ---------- 
    b         (所影响的行数为 1 行)
    */
    如果你的字段是varchar类型,pbsql(风云)原来的语句就是对的
      

  11.   

    回复  pbsql(风云):
      
      用你创建的表就可以,查询我在SQLSERVER上手动创建的表就返回所有记录,不知为啥?
      

  12.   

    多谢各位大侠,尤其是pbsql(风云)。本人用rea1gz(冒牌realgz V0.2) 的语句:
    select * from a t
     where not exists(select * from a where NH<>t.NH and NH like '%'+rtrim(t.NH)+'%')
       and not exists(select * from a where NH<>t.NH and t.NH like '%'+rtrim(NH)+'%')实现了我想要的结果,看来是我少见多怪了 :)
      

  13.   

    因为你给的数据有问题,你把题目中的a去掉,在将a12改为a2,按你的要求应该结果还是b,但用上面的方法就不对了
      

  14.   

    嘻嘻,like 条件写反了
    SELECT *
    FROM A M
    WHERE NOT EXISTS (
        SELECT TOP 1 1
        FROM A
        WHERE NH <> M.NH
            AND NH LIKE '%' + M.NH + '%'
    )