问一个sql中的group by问题

img


我已经在group by后面把字段都加入了,为什么还报这个错误:select子句后面的每一列非聚集表达式必须在group by后面出现

这个去掉

img

img

去掉2就可以了

group by后面不要带别名,select了啥就group by啥(除了聚合函数字段)

select a.stt_psn_type, a.med_pool_type, a.insutype,
nvl(a.grp_type, 'A') grp_type, nvl(sum(n), 0) amt
from tp.mdtrt_d a,
tp.setl_d b,
tp.setl_ext_d c
where a.mdtrt_id = b.mdtrt_id
and b.setl_id = c.setl_id
and a.vali_flag = '1'
and b.new_setl_id is null
and b.init_setl_id is null
and c.code = 'dejzyzje'
and nvl(c.n, 0) <> 0
and exists (select 'X'
from tp.setl_ext_d
where setl_id = c.setl_id
and code = 'hxjsh-2'
and c in (select year_end_setl_id
from tp.year_end_setl_d
where dfr_id = '1'))
group by a.stt_psn_type, a.med_pool_type, a.insutype,
nvl(a.grp_type, 'A')