Q:

Calculated column based on previous column

We have a table A as
amount numeric,
serial int,
due_date date,
rate numeric,
mi numeric

Sample Data:
amount.   rate.  due_date       mi.     serial
100000.   0.012.  '2017-01-01'   3000.    1
100000.   0.012.  '2017-02-01'   3000.    2
100000    0.012.  '2017-03-01'.  2000.    3
.
.
.

The amount column and rate are constant across rows.
I want to constuct a view for each row of the table as:
serial  opening      int_amount.  prncpl_amount.         prncpl_os
1.      amount          opening*0.012    mi-int_amount.   opening-prncpl_amount
2. previous(prncpl_os)  opening*0.012.   mi-int_amount.    opening-prncpl_amount       
.
.

I have tried using lag function, but since prncpl_os does not exist, it fails.
EDIT 1: The desired result would be 
serial.    opening.    int_amount.    prncpl_amount.  prncpl_os
1.         100000.      1200           1800          98200
2.         98200.       1178.40.       1821.60.      96378.40
3.         96378.40.    1156.54.       843.46.       95534.94

EDIT 2: The calculation mistake was corrected as pointed...

A:

You need a recursive CTE for this:
demo:db<>fiddle
WITH RECURSIVE next_ser AS (
    SELECT 
        a.*,
        lead(serial) OVER (ORDER BY serial) as next_serial
    FROM a
),
cte AS (

    SELECT
        serial,
        next_serial,
        amount AS opening,
        amount * rate AS int_amount,
        mi - (amount * rate) AS prncpl_amount,
        amount - mi + amount * rate AS prncpl_os
    FROM
        next_ser
    WHERE serial = 1

    UNION ALL

    SELECT
        a.serial,
        a.next_serial,
        c.prncpl_os,
        c.prncpl_os * a.rate,
        a.mi - (c.prncpl_os * rate),
        c.prncpl_os - mi + c.prncpl_os * rate
    FROM next_ser a
    JOIN cte c ON a.serial = c.next_serial
)
SELECT 
    serial, opening, int_amount, prncpl_amount, prncpl_os
FROM cte

The next_ser CTE is for calculating the next serial (in case they are not really consecutive) with help of the lead() window function which gets the values from the next records.
The recursion is straight-forward: The non-recursive part (the first SELECT statement of the UNION) is the starting point, which calculates your first row. The second part of the UNION is the recursive part of the CTE. Within that the last recursion step (JOIN cte) is joined against the row which has the serial id which equals the next_serial of the last recursion step. The previous prncpl_os value can be taken to be calculated with the current values...

