MYSQL的group_concat()函数中实现将多行同一字段数据合并成一个数据
数据表 出访团组表
Sql代码
select a.t_applypersondocno,a.t_id from sx_fms_taskinfo a
www.2cto.com
结果集
数据表 团组和国家关联表
Sql代码
select * from sx_fms_taskinfoid_countryid
结果集
数据表 国家信息表
Sql代码
select c_id,c_name from sx_fms_countryinfo
www.2cto.com
结果集
进行关联后将出访国家组合到一起(组合前)
Sql代码
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
组合前
进行关联后将出访国家组合到一起(组合后) 使用了 group_concat(c_name)
Sql代码 www.2cto.com
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
组合后