有两个客户基本信息表:需要将该两个客户基本信息表信息同步。现状:两个客户基本信息表都有重复的数据,可以不去更新重复的数据。
需求:通过p_customer_temp表更新custbaseinfo表数据,条件:通过 p_customer_temp表的cardid 匹配custbaseinfo表。
我的SQL语句:
select count(1) from p_customer_temp pc1 where exists
(select 1 from ( select cardid from p_customer_temp pct where pct.cardid is not null and pct.flag ='1' group by cardid having count(cardid) =1 ) pc2 where pc1.cardid = pc2.cardid)
and not exists (select 1 from custbaseinfo cust where exists(select 1 from custbaseinfo cust1 where cust1.crednum = cust.crednum)
and pc1.cardid = cust.crednum group by cust.crednum having count(cust.crednum)>1 )
求精辟的SQL语句!!!求优化!!!
需求:通过p_customer_temp表更新custbaseinfo表数据,条件:通过 p_customer_temp表的cardid 匹配custbaseinfo表。
我的SQL语句:
select count(1) from p_customer_temp pc1 where exists
(select 1 from ( select cardid from p_customer_temp pct where pct.cardid is not null and pct.flag ='1' group by cardid having count(cardid) =1 ) pc2 where pc1.cardid = pc2.cardid)
and not exists (select 1 from custbaseinfo cust where exists(select 1 from custbaseinfo cust1 where cust1.crednum = cust.crednum)
and pc1.cardid = cust.crednum group by cust.crednum having count(cust.crednum)>1 )
求精辟的SQL语句!!!求优化!!!
有时候要从数据库本身入手 索引 分区 临时表 少一些连接查询
并不是一条SQL都得到结果的方法就是好方法
begin
insert into t1
select * from t2
when exception then
null;
end;