gpt4 book ai didi

java - 关于oracle sql group by 'not a group by expression'

转载 作者:行者123 更新时间:2023-12-01 15:17:32 29 4
gpt4 key购买 nike

Oracle 10g,sql抛出异常:“not a group by expression”

select count(*)
from (
select h.personal_info_id pid,h.hbsag hbsag,h.sgpt sgpt,MAX(h.date_reported)
from health_checkup_info h
inner join personal_info p on h.personal_info_id = p.id
where
h.deleted = 0
and h.date_reported is not null
and h.hbsag in(1,2)
and p.deleted = 0

group by h.personal_info_id
) t where t.hbsag=1 and t.sgpt>=20

然后,我更改了“group by”参数,添加“h.hbsag”“h.sgpt”,例如:

group by h.personal_info_id,h.hbsag,h.sgpt

但结果不正确。

最佳答案

谢谢大家,现在我已经解决了问题。查询是:

select count(*)
from (
select h.personal_info_id pid,h.hbsag,ROW_NUMBER() OVER (partition by h.personal_info_id order by h.date_reported desc) r
from health_checkup_info h
inner join personal_info p on h.personal_info_id = p.id
where
h.deleted = 0
and h.date_reported is not null
and h.hbsag in(1,2)
and p.deleted = 0

) t where t.hbsag=2 and r=1

关于java - 关于oracle sql group by 'not a group by expression',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11427920/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com