SELECT
r.report_org_code AS orgCode,
r.report_org_type AS orgType,
r.report_org_name AS orgName,
r.report_quarter AS reportQuarter,
r.report_year AS reportYear,
r.report_time AS reportDate,
rtt.related_name AS relatedNames,
rt.product_name AS productName,
rt.product_scale AS productScale,
rt.product_ratio AS productRatio,
rt.shareholder_flag AS shareholderFlag,
GROUP_CONCAT(DISTINCT rtt.related_name
ORDER BY rtt.related_name ASC
SEPARATOR '、')
FROM
(
SELECT
*
FROM
t_multi_hi_related_trans
WHERE
report_id = 3
AND trans_type = '1'
AND credit_type = '04'
AND is_deleted = 'N'
AND history_id = (
SELECT
max( history_id )
FROM
t_multi_hi_related_trans
WHERE
report_id = 3)
) rt
LEFT JOIN t_multi_hi_related_trans_tgt rtt ON rtt.trans_num = rt.trans_num
AND rtt.history_id = rt.history_id
AND rtt.is_deleted = 'N'
LEFT JOIN t_multi_report r ON r.pid = rt.report_id
GROUP BY rt.pid
关键在于这个
GROUP_CONCAT(DISTINCT rtt.related_name
ORDER BY rtt.related_name ASC
SEPARATOR '、')
效果展示
标签:rt,不同,related,rtt,拼接,sql,report,trans,id From: https://www.cnblogs.com/bulesea/p/16803462.html