MySQL 行变列,去空,插入

 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'

你可能感兴趣的:(数据库,java,mysql,去空)