C表     字段(ID)  字段M   字段N  
A表插入   a        f      null  
A表插入   b        x      null  
B表插入   b        y       k  
B表插入   c        z       h  现在的情况是: 从A表中插两条记录到C表,从B表中也插两条记录到C表  
这样肯定会在"A.b = B.b"的这个地方出现异常.而使得C表无法正常显示.  
有什么好办法可以解决吗? 我隐约考虑到过滤,可是在什么时候过滤,又怎么过滤呢?  我最后的结果是要看到这样的效果  
C表     字段(ID) 字段M    字段N  
A表插入  a        f        g  
B表插入  b        y        k  
B表插入  c        z        h  也就是把A表插入的那一条N字段为NULL的那个重复ID(A.b)所在的一行记录给剔除掉.   注意:A表中的N字段,肯定都是null.赐教,在线等.谢谢!

解决方案 »

  1.   

    delete C from C t where id in (select id from C group by id having count(*) > 1) and N is null
      

  2.   


    delete from c cc
    where exists(select 1 from c where cc.c表=c表 and cc.字段(Id)<字段(Id))
    and 字段N is null
      

  3.   

    谢谢.请问 delete C from C t where ...  中的 "from C t" 是什么意思啊?
      

  4.   


    declare @c table(id varchar(10),m varchar(10),n varchar(10))
    insert into @c select 'a','f',null
    insert into @c select 'b','x',null
    insert into @c select 'b','y','k'
    insert into @c select 'c','z','h'
    delete @c where id in(select id from @c group by id having count(1)>1)
    and n is nullselect * from @c
      

  5.   

    同楼上的问。学习一下。DAWUGUI来解答一下
      

  6.   

    相当于from C as t
    取了个别名
      

  7.   

    如果 delete C from C t where id in (select id from C group by id having count(*) > 1) and N is null
    那么这条记录  "A表插入  a  f  null" 也插不进去了啊   
      

  8.   

    delete C from C t where id in (select id from C group by id having count(1) > 1) and N is null count(1) > 1 这个是对于一个ID重复的时候可以测试成功.  那如果现在有N个ID重复 怎么办?
      

  9.   

    N个重复的第三个字段是不是NULL
      

  10.   

    A表的N字段都是NULL现在的情况是 我让B表先插入 然后再插入A表 然后try catch中再加delete C from C t where id in (select id from C group by id having count(1) > 1) and N is null 
    结果是C表      ID        M       N
    B表插入   b        y       k   
    B表插入   c        z       h   我认为 "A表插入  a  f  null" 这个也可以插进C表的啊