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

后端 未结 6 1751
不思量自难忘°
不思量自难忘° 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:36

    Analytics are your friend:

    SELECT DISTINCT
           areas
          ,COUNT(currentitems.itemid)
           OVER (PARTITION BY areas) * 100
           / COUNT(*) OVER () Percentage
    FROM allitems, currentitems
    WHERE allitems.itemid = currentitems.itemid(+);
    

提交回复
热议问题