Re: More complex median calculation in Oracle SQL
From: Hans Mayr <mayr1972_at_gmx.de>
Date: Fri, 27 Aug 2010 00:09:20 -0700 (PDT)
Message-ID: <46d6617c-4cbd-44dc-a94a-029badf96877_at_v41g2000yqv.googlegroups.com>
Hello,
Date: Fri, 27 Aug 2010 00:09:20 -0700 (PDT)
Message-ID: <46d6617c-4cbd-44dc-a94a-029badf96877_at_v41g2000yqv.googlegroups.com>
Hello,
Thanks for your answers.
Mark: No, those functions don't do what I want. However I use 10g.
Joel: Yes, you are right, this is a solution. However I thought there might have been an easier solution than the following sql which's first line is the answer I look for.
select
unit_price, running_total / total as perc from (select unit_price, sum(total_turnover) over(order by unit_price ROWS UNBOUNDED PRECEDING) running_total, sum(total_turnover) over() total from (select unit_price, sum(unit_price * sold_units) total_turnover from tmp_articles group by unit_price order by unit_price ) ) where running_total / total >= 0.5 order by 1 ;
But on the other hand the sql is not so complicated for the very specific thing I was looking for. I just thought that within statistics such questions where very common and thus a predefined function would exist.
Best,
Hans Received on Fri Aug 27 2010 - 02:09:20 CDT