Home > Software design >  Big query/sql to maintain the same data from next row onwards in the same column itself, got based o
Big query/sql to maintain the same data from next row onwards in the same column itself, got based o

Time:01-08

I am working on one of the usecase where I need to implement one of the logic to get the relevant data .

eg: If you will see the image :

The column = new_TARIFF_ALLOWANCE_DATA is calculated as

case when gift_given!=0 or gift_received!=0 then TARIFF_ALLOWANCE_DATA - gift_given gift_received else remain same whatver it is as per last row calculation from next row onwards' as new_total_allwance

So basicall I want in the same column based on the condition whatver I got will maintain the same value from the next rown onwards in the same column

Expected output

More about LAST_VALUE navigation function: https://cloud.google.com/bigquery/docs/reference/standard-sql/navigation_functions#last_value

  • Related