假设我有数据库表X_tush,其中有列许可证,所以对于每个许可证说123我有n个与之关联的列,比如address_id,status,address_type等。 对于每个许可证我有n个网络说(101,102,108,113,114) 因此对于123许可证,存在101,102,114的3条记录和108,113的2条记录。 你能不能帮助复制101,102,114为113,108存在的记录,因为只有2条记录与之关联?
select * from xpna;
- 获取所需的所有网络
select distinct network from x_pns_address where network in (101,102,113,114,108
)进入临终;
- 识别所有具有5个以下网络的许可证
SELECT license,address_type ,contact ,address_line1,address_line2,city FROM xpna WHERE network IN (101,102,108,113,114) GROUP BY license,address_type ,contact ,address_line1,address_line2,city HAVING COUNT(network) < 5 into temp msn;
select * from msn,aln into temp table1;
- 在Temp表中插入缺失值
INSERT INTO xpna
SELECT n.license, n.network, n.address_type , n.contact , n.address_line1, n.address_line2, n.city FROM table1 as n
LEFT JOIN x_pns_address x
on x.network = n.network and x.license = n.license
group by x.address_type
where x.license is null;
select * from xpna;