DELETE FROM hunan_frk.each_corporate_portrait_label;
INSERT INTO hunan_frk.each_corporate_portrait_label (frwybs)
SELECT DISTINCT
frwybs
FROM
frk_anasi.enterprise_profile;
-- 插入法人的企业类型标签
UPDATE hunan_frk.each_corporate_portrait_label AS t1
SET enterprise_type = t2.label_content
FROM
(
SELECT
t1.frwybs,
COALESCE (t2.label_content, '') || ',' || COALESCE (t3.label_value, '') AS label_content
FROM
(
SELECT DISTINCT
t1.frwybs,
t1.label_module
FROM
frk_anasi.enterprise_profile t1
WHERE
t1.label_module = 'qylx'
) t1
LEFT JOIN (
SELECT
t1.frwybs,
t1.label_module,
t1.labelname,
t2.label_content
FROM
frk_anasi.enterprise_profile t1
LEFT JOIN frk_anasi.label_content t2 ON t1.label_module = t2.label_module
AND t1.labelname = t2.labelname
AND t1.label_value = t2.label_value
WHERE
t1.label_module = 'qylx'
AND t1.labelname = 'busstype'
) t2 ON t2.frwybs = t1.frwybs
LEFT JOIN (
SELECT
t1.frwybs,
t1.label_module,
t1.labelname,
t1.label_value
FROM
frk_anasi.enterprise_profile t1
WHERE
t1.label_module = 'qylx'
AND t1.labelname = 'isstate_owned'
) t3 ON t1.frwybs = t3.frwybs
) AS t2
WHERE
t1.frwybs = t2.frwybs;