sql语句,对比数据时候用到

来源:互联网 发布:ios11 数据流量开关 编辑:程序博客网 时间:2024/04/30 22:21

查询出有某两列相同的行:

select * from test a
where exists (
select 1
from test b
where b.学生姓名 = a.学生姓名
and b.手机号码 = a.手机号码
and (a.学校<> b.学校 or a.班级<> b.班级))


更改,合并某两项的数据:

update test1 set 手机1=(select distinct test2.手机1 from test2 where test2.学生姓名=test1.学生姓名 and test2.学号=test1.学号),
手机2=(select distinct test2.手机2 from test2 where test2.学生姓名=test1.学生姓名 and test2.学号=test1.学号)

原创粉丝点击