SQLite Forum

Help needed to return the right math results in sql query
Login
> In the spirit of gifting a fishing pole rather than fish

Thanks. Although, it won't do any good. I'm floating in outer space and there's no water in sight.


It turns out the query turns out to be much more complicated than I thought.

For the next value in the data, I need to subtract from previous and then do the multiplication to get the EG value.


```
SELECT *
 FROM (
  SELECT
	lag(TID, 1,0) OVER
	w current_TID, TID as next_TID,
	(TID) - (lag(TID,1,0) OVER w) EG
  FROM CalculateGrowth
  WINDOW w AS (PARTITION BY PIG ORDER BY PIG)
) e
WHERE EG IS NOT NULL;
```

Not quite sure, yet, where to fit in the difference between the TID*0.003*250

```
(TID) - (lag(TID,1,0)*0.003*250
```

doesn't work