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

Re: Best method to use LAG - A window function in Scripted calculation View.

$
0
0

Hi Kumar,

 

Here's my recommendation. As always there's likely quite a few solutions. But here's where I'd start.

 

First, a question - you describe dates i.e. June 1, June 2 - but in your SQL I see TRADE_ID. I'm going to assume TRADE_ID is date-related, some kind of chronological indicator, of type INTEGER.

 

1) Create a new "generated column" (persisted calculated field) as follows:

ALTER TABLE "WORKSHOP"."CP_TRADE_TRNSCT_NEW" ADD ("TRADE_ID_NEXT" INTEGER GENERATED ALWAYS AS "TRADE_ID" + 1);


2) Self join the table to itself, on all required key fields, plus T1.TRADE_ID = T2.TRADE_ID_NEXT


3) Do the calculation subtracting amounts.


All of the above can be done graphically very easily - except the generated column of course, you have to execute that command (and make sure it's somehow maintained in case table gets dropped for some reason).


Details on generated columns (scroll down a bit, also do a google search for more related topics) - ALTER TABLE - SAP HANA SQL and System Views Reference - SAP Library

 

Also, as noted above - window functions execute in row store, hence the slower performance.

 

Cheers,

Jody


Viewing all articles
Browse latest Browse all 8667

Trending Articles



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