MySQL 行变列,去空,插入

本文介绍了如何在MySQL中通过UNION操作,结合COALESCE函数处理行变列,移除空值,实现数据合并,以满足特定的业务需求,如biz_email表的插入操作。
摘要由CSDN通过智能技术生成

 MySQL 行变列,去空,插入

INSERT INTO biz_email(be_company_id,be_email_address,be_scope,be_carbon_action,be_in_active)

SELECT custno,To1,2,1,1 FROM `temp_biz_email3`  WHERE COALESCE(To1,"abc") !='abc'

UNION

SELECT custno,To2,2,1,1 FROM `temp_biz_email3`  WHERE COALESCE(To2,"abc") !='abc'

UNION

SELECT custno,To3,2,1,1 FROM `temp_biz_email3`  WHERE COALESCE(To3,"abc") !='abc'

UNION

SELECT custno,To4,2,1,1 FROM `temp_biz_email3`  WHERE COALESCE(To4,"abc") !='abc'

UNION

SELECT custno,To5,2,1,1 FROM `temp_biz_email3`  WHERE COALESCE(To5,"abc") !='abc'

UNION

SELECT custno,To6,2,1,1 FROM `temp_biz_email3`  WHERE COALESCE(To6,"abc") !='abc'

UNION

SELECT custno,To7,2,1,1 FROM `temp_biz_email3`  WHERE COALESCE(To7,"abc") !='abc'

UNION

SELECT custno,To8,2,1,1 FROM `temp_biz_email3`  WHERE COALESCE(To8,"abc") !='abc'

UNION

SELECT custno,To9,2,1,1 FROM `temp_biz_email3`  WHERE COALESCE(To9,"abc") !='abc'

UNION

SELECT custno,To10,2,1,1 FROM `temp_biz_email3`  WHERE COALESCE(To10,"abc") !='abc'

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值