select mo.organ_id orgId,--专员所属三级机构
mo.abbr_name orgName,
md2.departid group2Id,--专员所属部
md2.departname group2Name,
md3.departid group3Id,--专员所属组
md3.departname group3Name,
m.empno monitorId, --专员
m.name monitorName,
ad2.departid departid2,--业务员所属部
ad2.departname departname2,
ad3.departid departid3,--业务远所属组
ad3.departname departname3,
(select count(*)
from rm_bm_agent_monitor_relation r
where r.depart3_id = rel.depart3_id) totalPer,
(select count(*)
from rm_bm_agent_monitor_his h
where h.agent_id = his.agent_id) exceutePer,
rel.execute_month executeMonth
from rm_bm_agent_monitor_relation rel, --计划时间区间内
rm_bm_agent_monitor_his his,
rm_em_cm_agent m, --专员
rm_em_cm_agent a, --业务员
rm_md_organazition mo, --专员所属三级机构
rm_em_cm_department md2, --专员所属部
rm_em_cm_department md3, --专员所属组
rm_em_cm_department ad2, --业务员所属部
rm_em_cm_department ad3 --业务远所属组
where rel.agent_id = his.agent_id
and rel.monitor_id = his.monitor_id
and rel.agent_id = a.empno
and rel.monitor_id = m.empno
and rel.depart2_id = ad2.departid(+)
and rel.depart3_id = ad3.departid(+)
and rel.group1_id = md2.departid
and rel.group2_id = md3.departid
and rel.orgid = mo.organ_id(+)
and rel.execute_month = his.execute_month
and a.jobcode = '1'
and m.jobcode = '1'
and a.status = '1'
and m.status = '1'
and rel.status = '1'
and his.status = '1'
and m.agenttype = '5'
and m.orgid = '10400'
and rel.execute_month = '201805'
and m.depart_id = '5104000000701'
and rel.monitor_id in ('47210428')
and rel.depart3_id in ('5104000000701')
and rel.execute_date >= (to_date('2018-05-10', 'yyyy-MM-dd'))
and rel.execute_date <= (to_date('2018-05-18', 'yyyy-MM-dd'))
group by mo.organ_id
如上面的sql,group by后面必须加上你select后面所查询的所有除聚合函数之外的所有字段。
解决方法:将group by放入子查询中使用或者将select后面的所有查询字段放入group by 后。