Mysql插入数据从另外一个表查询,并且动态判断值展示。
其他细节待补充。
分析:
SELECT cpn_name,cpn_type,sub_code,
IF(1=1, (SELECT * FROM (SELECT id FROM B表 WHERE TYPE = 4 AND NAME = '七号楼') X), 0) AS 'building_number'
,(SELECT b.id FROM B表 b JOIN smart_therm.t_ly_cpn a ON a.floor = b.mapping_value
WHERE a.id = X.id AND b.type = 5) AS FLOOR,group_id,show_name,sub_system_flag,is_show,location,true_cpn_name,assist_cpn_name,dev_num,AREA,remark,module_name,district FROM A表 X ;
INSERT? ?INTO? 新表 (字段1,字段2,字段三,......)
SELECT 字段1,字段2,
IF(1=1, (SELECT * FROM (SELECT id FROM? B表 WHERE TYPE = 4 AND NAME = '七号楼') X), 0) AS 'building_number'
,字段N FROM A表 ;