选择Distinct值并插入到返回重复项的表中



我的表Data_Excel有人的详细信息:P_name,P_address,P_city,表PersonID,startdate,enddate,我必须在Person_location中插入以下值ID,address,city,country,startdate,enddate,问题是我想在以ID,StartDate为主键的person_location中插入值,我尝试了以下查询,但有一些结果如下:

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 

Hello'user408437'此查询适用于在您的表上获取重复行

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

如果你的替换>符号from=,那么他得到每重复行的单行

我希望这对你的来说是一件小事

最新更新