0

名、姓、生年月日が同じレコードを引き出す必要があります。以下の例をご覧ください。

Employeeid   firstname lastname DOB
00010         ravi      sagi     22/01/1990
00035         ravi      sagi     22/01/1990
00060         vasanth   guptha   20/01/1987
00115         vasanth   guptha   20/01/1987

質問を書くのを手伝ってくれませんか。

4

2 に答える 2

4

これを試して:

select *
from
  (
    select *,
           count(*) over(partition by firstname, lastname, DOB) as CC
    from YourTable
  ) as T
where T.CC > 1
于 2012-08-27T13:44:53.503 に答える
1

JOINテーブルをそれ自体と比較してfirstnamelastnameを比較し、DOBそれらが同じ値であることを確認してから、が同じでないことを確認できますemployeeid

select * 
from yourtable t1
inner join yourtable t2
  on t1.firstname = t2.firstname
  and t1.lastname = t2.lastname
  and t1.dob = t2.dob
  and t1.empid != t2.empid

上記のクエリは重複するレコードを表示する可能性があるため、以下を使用できます(SQL Fiddle with Demoを参照)。

select DISTINCT t1.empid,
  t1.firstname,
  t1.lastname,
  t1.DOB
from yourtable t1
inner join yourtable t2
  on t1.firstname = t2.firstname
  and t1.lastname = t2.lastname
  and t1.dob = t2.dob
  and t1.empid != t2.empid

または、次を使用することもできますEXISTSデモ付きのSQLフィドルを参照)。

select t1.empid,
  t1.firstname,
  t1.lastname,
  t1.DOB
from yourtable t1
where exists (SELECT *
              FROM yourtable t2
              WHERE t1.firstname = t2.firstname
                and t1.lastname = t2.lastname
                and t1.dob = t2.dob
                and t1.empid != t2.empid)
于 2012-08-27T13:47:33.933 に答える