目前我把SQL改了,可以运行了,我把left join kl_conm_ycenterprise_withcert wi on wi.conmid = d.baseid改到了子查询里面,和kl_conm_base关联,外面用group_concat(distinct wc_person_name)就能查出来了
select d.*,group_concat(distinct wc_person_name) 人才选择
from (
select suser.realName 所属人,
base.id baseid,
luser.realName 录入人,
resuser.realName 申请人,
sdept.d4 大区,
sdept.d5 分公司,
concat_ws('/', sdept.d4, sdept.d5, sdept.d6, sdept.d7) 部门,
contract_no,
price 合同金额,
kickback 咨询费,
FROM_UNIXTIME(contract_signing_time) 签约时间,
case
when base.state = 2
then '已签约'
when base.state = 3
then '合同执行中'
end as 合同状态,
ent_name 企业名称,
ent_linkman 联系人,
config.name 操作状态,
config2.name 核款状态,
FROM_UNIXTIME(xxf.create_time) 申请时间,
# xxf.state 操作状态,
xxf.transfer_price 转业绩金额,
(select sum(transfer_price)
from kl_conm_account
where qconmid = base.id
and state in (12, 14)
and conmid = 0) 入账总金额,
base.id,
wi.wc_person_name
from ods_oa.kl_conm_base base
left join ods_oa.kl_users suser on base.ouid = suser.ID
left join ods_oa.kl_users luser on base.uid = luser.ID
left join ods_oa.dept_ext sdept on sdept.id = suser.DEPARTMENTID
left join kl_conm_ycenterprise qy on qy.conmid = base.id
left join kl_conm_account_xxf xxf on xxf.conmid = base.id
left join kl_conm_account_result res on res.cid = base.id and is_zx = 2
left join kl_status_config config on config.id = xxf.state
left join kl_status_config config2 on config2.id = entry_status
left join ods_oa.kl_users resuser on resuser.id = xxf.uid
left join kl_conm_ycenterprise_withcert wi on wi.conmid = base.id
where suser.realName in (
select 所属人
from (
select suser.realName 所属人
from ods_oa.kl_conm_base base
left join ods_oa.kl_users suser on base.ouid = suser.ID
left join kl_conm_account_xxf xxf on xxf.conmid = base.id
where contract_no like '%Q%'
and xxf.transfer_price > 0
group by contract_no
) t
group by t.所属人
having count(t.所属人) > 1
)
and contract_no like '%Q%'
and xxf.transfer_price > 0
group by contract_no, suser.realName
order by suser.realName) d
group by d.contract_no, 所属人
order by 所属人