MYSQL的group_concat()函数中实现将多行同一字段数据合并成一个数据

数据表 出访团组表
select a.t_applypersondocno,a.t_id from sx_fms_taskinfo a

结果集
MYSQL的group_concat()函数中实现将多行同一字段数据合并成一个数据

数据表  团组和国家关联表
select * from sx_fms_taskinfoid_countryid

结果集
MYSQL的group_concat()函数中实现将多行同一字段数据合并成一个数据

数据表  国家信息表
select c_id,c_name from sx_fms_countryinfo

结果集

MYSQL的group_concat()函数中实现将多行同一字段数据合并成一个数据


进行关联后将出访国家组合到一起(组合前)
select taskinfo.t_applypersondocno, countryinfo.c_name from sx_fms_taskinfo taskinfo
left join sx_fms_taskinfoid_countryid tcinfo 
on taskinfo.t_id = tcinfo.t_id 
left join sx_fms_countryinfo countryinfo
on tcinfo.c_id = countryinfo.c_id 

组合前

MYSQL的group_concat()函数中实现将多行同一字段数据合并成一个数据


进行关联后将出访国家组合到一起(组合后) 使用了 group_concat(c_name)
select taskinfo.t_applypersondocno,group_concat(c_name) from sx_fms_taskinfo taskinfo
left join sx_fms_taskinfoid_countryid tcinfo 
on taskinfo.t_id = tcinfo.t_id 
left join sx_fms_countryinfo countryinfo
on tcinfo.c_id = countryinfo.c_id 
group by taskinfo.t_applypersondocno 

组合后

MYSQL的group_concat()函数中实现将多行同一字段数据合并成一个数据

你可能感兴趣的:(sql,mysql)