我必须检索一些数据(Oracle RDBMS)。我必须过滤它们,给它们加油。所以我想做三个嵌套查询 从外部开始:用于限制查询以对其进行排序的查询和用于选择的查询(还对其进行过滤和分组)。 这是查询:
@SqlQuery("select count(*) personCount, SURNAME surname, SKILL skill, ROWNUM " +
" from (select * " +
" from (select count(*) personCount, SURNAME surname, SKILL skill from people " +
" where ....my filters....
" group by SURNAME, SKILL ) " +
" order by personCount DESC ) " +
" where ROWNUM \\<= :limit ")
但它给了我这个错误:ORA-00937: it is not a group function on only one grouping
为什么?
答案 0 :(得分:1)
您不能在外部选择中进行计数:
@SqlQuery("select personCount, surname, skill, ROWNUM " +
" from (select * " +
" from (select count(*) personCount, SURNAME surname, SKILL skill from people " +
" where ....my filters.... "
" group by SURNAME, SKILL) " +
" order by personCount DESC ) " +
" where ROWNUM \\<= :limit ")
答案 1 :(得分:1)
您必须指定在group by
子句中选择的所有列:
@SqlQuery("select personCount, SURNAME surname, SKILL skill, ROWNUM " +
" from (select * " +
" from (select count(*) personCount, SURNAME surname, SKILL skill from people " +
" where ....my filters.... " +
" group by SURNAME, SKILL ) " +
" order by personCount DESC ) " +
" where ROWNUM \\<= :limit ")
此外,您已计算了personCount的计数,您无需再次计算。
请注意,我将知识列替换为组中的技能列,我认为这是一个错字。