How to resolve ORA-00937: not a single-group group function when calculating percentage?

后端 未结 6 1711
不思量自难忘°
不思量自难忘° 2021-01-18 05:08

I\'m trying to get a percentage of the itemid that are available in a certain area. Using my query, I get an error ORA-00937: not a single-group group function<

6条回答
  •  离开以前
    2021-01-18 05:27

    Here is a quick first pass:

    select ai.areas,
           (sum(cnt) / max(tot)) * 100 "Percentage Result"
      from (select ai.itemid,
                   ai.areas,
                   count(ci.itemid) cnt,
                   count(ai.areas) over () tot
              from allitems ai
                   left outer join
                   currentitems ci on (ai.itemid = ci.itemid)
            group by ai.itemid, ai.areas
           ) ai
    group by ai.areas
    

    Also, in your test data your itemid 4 needs to be changed to west.

提交回复
热议问题