Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 8950

Re: Difficult to decide on which way is better

$
0
0

Well actually you can lower that down to a single (&sad) select SQL by using SUM as a window function as well:

 

select  CALMONTH,  INDIVIDUAL_CNT,  TOTAL,  PERCENTAGE,  RANK,  (CASE WHEN RANK<=0.8 THEN 'Fast'         WHEN RANK > 0.8 and RANK <= 0.95  THEN 'Medium'            ELSE 'Slow'      END) as RANK_STR
from (select        CALMONTH,        INDIVIDUAL_CNT,        TOTAL,        round(to_decimal(INDIVIDUAL_CNT/total)*100, 4) PERCENTAGE,        percent_rank() over (order by round(to_decimal(INDIVIDUAL_CNT/total)*100,4) desc) as rank   from (select                CALMONTH,                 INDIVIDUAL_CNT,             SUM(INDIVIDUAL_CNT) over () as total              from (                   select left(replace(FLDATE,'-',''), 6) as calmonth,                           count(BOOKID) as individual_cnt from SAPABAP1.SBOOK              group by left(replace(FLDATE,'-',''),6)))) 

Performance was actually good (considering I'm using a single small table and not a complex view): total execution of 3.8s with 2.9s on JECalculate (replace and left function on the innermost select query). So if you don't have to calculate anything it should be wa(a)aay faster. It also consumed 3.6GB to execute it in my case:

 

2016-07-05_16-13-08.jpg

 

ps.: Still haven't tried with WITH clause.

 

BRs,

Lucas de Oliveira


Viewing all articles
Browse latest Browse all 8950

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>