表X
id  B  C  D 0  2  3  4 1  6  7  8 2  2  8  4 
第一条和第四条数据 B、D字段值相同,如何将其查出来 (详细说明下,谢谢)

解决方案 »

  1.   

    select a.B,a.D from x a, x b where a.B=b.B and a.D=b.D
      

  2.   

    select * from table1 t where (select count(1) from table1 where b=t.b and d=b.d)>1
      

  3.   

    select a.* from x a inner join x b on a.b = b.b and a.d=b.d
      

  4.   

    select * from x where b in (select b from x) and d in (select d from x)
      

  5.   

    declare @t table(id int,  B int,  C int, D int) 
    insert @t select 0,  2,  3,  4 
    insert @t select 1,  6,  7,  8 
    insert @t select 2,  2,  8,  4 
    select * from @t t where  exists(select 1 from @t where B=t.B and D=t.D and ID<>t.ID )
      

  6.   

    select * from test a, test b where a.B=b.B and a.D=b.D and a.ID<>b.ID
      

  7.   

    select * from table_Pqs Pqs 
     where Exists(select 1 from table_Pqs 
     where b=Pqs.b and d=Pqs.d And id<>table_Pqs.id)
      

  8.   


    --如果想直接排列出顺序,便于查看就加上排序
    select * from table_Pqs Pqs 
     where Exists(select 1 from table_Pqs 
     where b=Pqs.b and d=Pqs.d And id<>table_Pqs.id)
     Order By b,d--如果作为一条记录显示 那就如上用inner join方式,但就结果而言应该是反复出现了2次
      

  9.   


    select a.B,a.D from x a, x b where a.B=b.B and a.D=b.D