2013-11-27 75 views
0

我有具有人的詳細信息表Data_ExcelP_name,P_address,P_city並具有ID,startdate,enddatePerson,我在Person_location以下值ID,address,city,country,startdate,enddate插入值,問題是,我要插入在person_location具有ID,StartDate作爲主鍵我嘗試以下QUERY值但有一些結果如下:選擇不同的值,並插入到表中返回重複

SELECT Distinct A.ID,A.name,A.startdate,A.enddate,de.source,de.P_address,de.P_city,de.P_country 
    from data_excel de, person A 
    where A.name = de.P_name 
    and ID > 6566; 

結果:

`7552 Adan George H. 30/12/1928 31/12/1928 Recueil Financier 1928 Avenue des Trois Couleurs 17 Woluwe-Saint-Pierre (Bruxelles) 
    7552 Adan George H. 30/12/1928 31/12/1928 Recueil Financier 1928 Avenue des Trois Couleurs 17 Woluwe-Saint-Pierre (Bruxelles) Belgie 
+0

Data_excel有多個輸入人名和地址,Id來自person表,我必須從person表比較名稱和data_excel中獲取id並獲取位置詳細信息,並最終在Person_location中插入id和位置表 –

+0

那麼哪一排你想用插入和如何描述。最早的一個,最近的? –

回答

0

你好「user408437」爲得到你的表

with cte as 
(
    select *,rn= ROW_NUMBER() over (partition by id order by id) from tablename 
) 
select * from cte where rn>1 

重複行,如果該查詢工作你更換>從等號(=)那麼他得到的所有重複的行單列

我希望這是小對你的工作

+0

我追加這部分在我的查詢結束? –

相關問題