求一SQL语句实现数据表之间的去重复项如有一表AT 中有四个字段a b c d 其中 a字段,b字段,c字段为联合主键
数据如下a b c d
1 11 22 aa
1 22 22 bb
1 33 22 cc
2 11 22 dd有另一张表AT_Temp临时表
也有四个个字段a b c d 其中 a字段,b字段,c字段为联合主键
数据如下
a b c d
1 22 22 bb
1 22 33 ff
2 11 44 gg请问如何实现AT_Temp表中与AT表去掉重复记录并将不重复数据插入到AT表中我如道如果只有一个主键 a 的话用insert into AT select * from A_Temp from a not in (select a from AT) 可以做出来,但当他有三个主键
后我在后面中 and b not in (select b from AT) ... 是不可行的,并且效率低,求一好的SQL
数据如下a b c d
1 11 22 aa
1 22 22 bb
1 33 22 cc
2 11 22 dd有另一张表AT_Temp临时表
也有四个个字段a b c d 其中 a字段,b字段,c字段为联合主键
数据如下
a b c d
1 22 22 bb
1 22 33 ff
2 11 44 gg请问如何实现AT_Temp表中与AT表去掉重复记录并将不重复数据插入到AT表中我如道如果只有一个主键 a 的话用insert into AT select * from A_Temp from a not in (select a from AT) 可以做出来,但当他有三个主键
后我在后面中 and b not in (select b from AT) ... 是不可行的,并且效率低,求一好的SQL
insert into AT
select * from A_Temp from a
where not exists(select 1 from at b where a.a=at.a and a.b=at.b and a.c=at.c)
select * from A_Temp from a
where not exists(select 1 from at b where a.a=b.a and a.b=b.b and a.c=b.c)
select * from A_Temp a
where not exists(select 1 from at b where a.a=b.a and a.b=b.b and a.c=b.c)
insert into AT
select * from A_Temp from a
where not exists(select 1 from at where a.a=at.a and a.b=at.b and a.c=at.c)
name,
classid,
counts,
classname
FROM
merchant
WHERE
counts in
(
SELECT
max(counts)
FROM
merchant
GROUP BY
classname
)
ORDER BY
counts asc