I\'d like to create a view in SQLite where a field in one row depends on the value of a field in the previous row. I could do this in Oracle using the LAG
analy
Oracle equivalent is correct. Starting from SQLite 3.25.0 you could use LAG
natively:
WITH mytable(ITEM,DAY,PRICE) AS (
VALUES
('apple', CAST('20110107' AS DATE), 1.25),
('orange', CAST('20110102' AS DATE), 1.00),
('apple', CAST('20110101' AS DATE), 1.00),
('orange', CAST('20110103' AS DATE), 2.00),
('apple', CAST('20110108' AS DATE), 2.00),
('apple', CAST('20110110' AS DATE), 1.50)
)
SELECT day, price, price-LAG(price) OVER (ORDER BY day) AS change
FROM mytable
WHERE item = 'apple'
ORDER BY DAY;