当前位置: 代码迷 >> Sql Server >> sql insert into select where 复制表对于重复的数据进展过滤
  详细解决方案

sql insert into select where 复制表对于重复的数据进展过滤

热度:20   发布时间:2016-04-24 09:47:46.0
sql insert into select where 复制表对于重复的数据进行过滤
sql insert into select where 复制表的对于重复的数据进行过滤
Student的数据导入到 Person  要求过滤掉 同一条数据里面 姓名和年龄同时相同的数据







我的SQL语句时错误的


insert into dbo.Person(姓名,年龄) select 姓名,年龄 from dbo.Student where (Student.姓名 not in (select 姓名 from Person) and Student.年龄 not in (select 年龄 from Person))

我是新手,求各位前辈指导
------解决思路----------------------
引用:
sql insert into select where 复制表的对于重复的数据进行过滤
Student的数据导入到 Person  要求过滤掉 同一条数据里面 姓名和年龄同时相同的数据







我的SQL语句时错误的


insert into dbo.Person(姓名,年龄) select 姓名,年龄 from dbo.Student where (Student.姓名 not in (select 姓名 from Person) and Student.年龄 not in (select 年龄 from Person))

我是新手,求各位前辈指导
   
  
 --查询方式1
  SELECT [姓名],[年龄],[班级],[手机] FROM (
  SELECT  ROW_NUMBER()  OVER(PARTITION BY [姓名],[年龄]  ORDER BY [姓名]) AS ID,*  FROM student 
  )a WHERE a.ID=1
  
---查询方式2
  
 SELECT * FROM  student WHERE   student.%%physloc%% IN (SELECT MIN(student.%%physloc%%) FROM student GROUP BY  [姓名],[年龄] ) 

------解决思路----------------------
1楼请原谅,原谅我一眼瞅去把你名读错。

想问下楼主为何要这么处理,studentu插入到person中……现实中不应该反过来吗???
------解决思路----------------------
你是要做什么呢了

提取studentu不重复的数据插入到person?

提取studentu不存在于person的数据插入到person?

合并两张表的数据到person,并过滤掉重复的数据?
  相关解决方案