完整的语法
group_concat([DISTINCT] 要连接的字段 [Order BY ASC/DESC 排序字段] [Separator ‘分隔符’])
查询发票明细表,单张发票对应的所有明细的所有税率,以逗号拼接
select invoice_no,GROUP_CONCAT(DISTINCT tax_rate separator ';') as tax_rate
FROM pdt_d_income_invoice_detail
WHERE
tax_rate is not null
and deleted = 0
GROUP BY invoice_no,invoice_code
查询结果
解释说明
group_concat()拼接查询出来的所有结果
group_concat(DISTINCT) 过滤拼接后相同的数据达到所期望的效果
评论区