s_id  name 
1      a
2      b
3       a
2      b
4       c
6       t
7        r
8         t
9        q
10       m
10       c
11        g_________________删除所有name只关联一个s_id记录怎么写?

解决方案 »

  1.   

    delete tb
    where name in(select namem from tb group by name having count(1)=1)
      

  2.   

    delete a
    from ta a
    where exists(select 1 from ta where name = a.name and s_id < a.s_id)
      

  3.   

    delete t from tb t where name in( select name from tb group by name having count(1)=1)
      

  4.   


    小f??
    为什么是count(1)了???
      

  5.   


    group by  以后可以用 count(1) 这个地方count(1)=count(name)
      

  6.   


    统计同一个name的s_id个数
      

  7.   

    我习惯 count(1) count(2) 也可以 
      

  8.   


    declare @table table(id int,name varchar(50))
    insert into @table
      select 1 , 'a'
    union all select 2,  'b'
    union all select 3,   'a'
    union all select 5 ,  'b'
    union all select 4 ,  'c'
    union all select 6 , 't'
    union all select 7 ,  'r'
    union all select 8 , 't'
    union all select 9 ,  'q'
    union all select 10 ,'m'
    union all select 10, 'c'
    union all select 11,'g' select * from @tabledelete A from @table a where not exists(select * from @table
     where name=a.name and id<>a.id)
     
     select * from @table