码迷,mamicode.com
首页 > 数据库 > 详细

mysql ||

时间:2021-03-31 12:35:16      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:cat   agent   sel   res   article   net   ike   csdn   rem   

将多条记录的某个字段合并成一条记录

group_concat : 将某字段多条记录合并,默认逗号分隔

select group_concat(c.invoice_no) from ibc_comm_invoice c where c.settle_nos like concat(‘%‘,m.settle_no,‘%‘) 

group_concat(xxx separator ‘符号‘) : 以 "符号"分割

select group_concat(c.invoice_no separator ‘;‘) from ibc_comm_invoice c where c.settle_nos like concat(‘%‘,m.settle_no,‘%‘)

sql

select  m.id,m.settle_no,m.fee_type,m.org_code,m.person_code,m.person_name,m.team_code,
m.agent_code,m.agent_name,m.company_code,m.company_name,m.sum_policy_premium,
m.policy_currency,m.exchange_rate,m.fee_currency,m.sum_fee,m.created_by,m.created_date,
m.updated_by,m.updated_date,m.payment_fee,m.payment_date,m.resultFlag,
(select group_concat(c.invoice_no) from ibc_comm_invoice c where c.settle_nos like concat(‘%‘,m.settle_no,‘%‘) ) invoice_no,
(SELECT c.code_name FROM sys_d_code c WHERE c.code_type = ‘BillStatus‘ AND c.code_code = m.valid_status)valid_status,
(SELECT c.code_name FROM sys_d_code c WHERE c.code_type = ‘invoiceStatus‘ AND c.code_code = m.invoice_status)invoice_status,
(SELECT c.code_name FROM sys_d_code c WHERE c.code_type = ‘PaymentStatus‘ AND c.code_code = m.payment_flag)payment_flag   
from ibc_comm_main m 

参考博客 : https://blog.csdn.net/qq_14852397/article/details/47167401

mysql ||

标签:cat   agent   sel   res   article   net   ike   csdn   rem   

原文地址:https://www.cnblogs.com/wuzimeimei/p/14600184.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!