SQLite Forum

More math help and what I've learned
Login
Hello MBL! My goodness, that is so awesome. Thank you for assisting and showing me the `else` usage. I didn't consider it or know about it.

This now gets me the diff column correctly! The very minor thing that was aggravating was realizing I needed to do `1000000.0`, otherwise the values were 0.25 off.



```
SELECT *,
       CASE
           WHEN previous_transId IS NULL THEN growthpool/1000000.0-EstGrowth
           ELSE (growthpool-Previous_GCOV)/1000000-EstGrowth
       END AS diff
FROM
  (SELECT GrowthPool,
          TransactionId AS current_transId,
          lag(GrowthCarry) OVER w Previous_GCOV,
                                GrowthCarry AS Current_GCOV,
                                (lag(GrowthCarry) OVER w) AS GCOVAW,
                                lag(TransactionId) OVER w AS previous_transId,
                                                        CASE
                                                            WHEN lag(TransactionId, 1) OVER w THEN ((TransactionId) - (lag(TransactionId) OVER w))*0.003*250
                                                            ELSE TransactionId *0.003*250
                                                        END AS EstGrowth
   FROM CalculateGrowth2 WINDOW w AS (PARTITION BY PIG
                                      ORDER BY PIG)) e
WHERE EstGrowth IS NOT NULL
```

Thank you for your help!