sql查询的结果,其他字段相同,就一个不同,合并后不同的字段数值拼接

 

 

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 '、')

 

效果展示

 

posted @ 2022-10-18 17:39  蓝海的bug本  阅读(286)  评论(0编辑  收藏  举报