1

2 つ以上のレコードの生年月日が同じであるが、person_id が等しくない結合から結果を返したいです。オラクルを使用しています。したがって、行 1 と行 2 の生年月日が同じで person_id が異なる 4 つの結果が得られた場合、それらの行が返されます。行 3 と 4 に同じbirth_date と同じ person_id がある場合、それらの行は返されません。結果が得られましたが、行の生年月日が等しい結果をフィルタリングしたいのですが、person_id は <> です。

  select t3.field1, t6.field2, t6.field3, t3.field4, t3.field5 
from table1 t1
    inner join table2 t2 on t1.@matching = t2.@matching
    inner join table3 t3 on t3.@matching = t1.@matching
    inner join table4 t4 on t4.@matching = t1.@matching
    inner join table5 t5 on t5.@matching = t4.@matching
    inner join table6 t6 on t6.@matching = t3.@matching
      where t1.@requirement = 'xxx' 
      and t2.@requirement = 'xxx' 
      and t2.@requirement is null 
      and t4.@requirement = 'xxx'
      and t5.@requirement = 'xxx' 
      and t1.@requirement ='xxx' 
      and t5.@requirement is null 
    order by t1.@field ASC;
4

2 に答える 2

0

データを person_id でグループ化しようとしましたか?これにより、同じ person_id を持つすべてのレコードが 1 つのレコードにまとめられます。

クエリは次のようになります

 SELECT a.birth_date, a.id, b.id
 FROM   some_table a, some_table b
 WHERE  a.birth_date = b.birth_date
 AND    a.id < b.id
 GROUP BY a.id
于 2013-11-08T16:27:42.723 に答える