有表格table,字段有N1,N2,N3,N4等等,现在要筛选出N1相同,但是N3不同的记录,如何写这个SQL?

解决方案 »

  1.   

    SELECT * FROM myTable WHERE N1='N1' AND N3<>'N3'
      

  2.   

    N1,N3这是字段名称啊,这样写不成了N1=某个值的,和N3不等于某个值的了吗?
      

  3.   

    select * from table a where (n1 in (select n3,n1 from table where a.n3<>n3))
      

  4.   

    没有关键字段怎么弄呢?
    select N3 from Table group by N3 having count(N3)>1
      

  5.   

    select * from table a where (n1 in (select n3,n1 from table where a.n3<>n3))
      

  6.   

    select * from table a where (n1 in (select n3,n1 from table where a.n3<>n3))
    运行不过
      

  7.   

    select distinct N1,N3 
    Into #Tmp
    From table(nolock)Select * 
    From table(nolock)
    Where N1 in (Select N1 From #Tmp Group N1 Having count(*)>1) 
      

  8.   

    SELECT * FROM table a WHERE (n1 IN(SELECT n1 FROM table WHERE a.n3<> n3))
      

  9.   

    select N1,N3 from table group by N1,N3
      

  10.   

    select * form table where N1 not in(select N1 from table group N1,N3) group N1  
      

  11.   

    sql版有高手无数,是论坛中技术水平最高的版块。应该发到sql版块select * from a where n1 in (select n1 from a group by n1 having count(*)>1)
    and n1 in (select n1,n3 from a group by n1,n3 having count(*)=1)