Search code examples
sqlteradatateradata-sql-assistant

Teradata Sql, trying to achieve rate of interest


I was trying to achieve the below result:

enter image description here

The logic for the 1st row is, ((470-375)/375)*100 If someone has idea about this please contribute.


Solution

  • You can use window function lead() to retrieve the cumulative_excp of the next record, and then use it in the computation:

    select 
        run_date, 
        cumulative_excp,
        100.0 
            * (lead(cumulative_excp) over(order by run_date) - cumulative_excp) 
            / cumulative_excp interest
    from mytable