By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE tablename (
`week` INTEGER,
`sales` INTEGER
);
✓
INSERT INTO tablename
(`week`, `sales`)
VALUES
('22', '11'),
('21', '63'),
('20', '78'),
('19', '170'),
('18', '130');
✓
SELECT *,
ROUND(100.0 * (1.0 * sales / LAG(sales) OVER (ORDER BY week) - 1), 1) growth
FROM tablename
ORDER BY week DESC;
week | sales | growth |
---|---|---|
22 | 11 | -82.5 |
21 | 63 | -19.2 |
20 | 78 | -54.1 |
19 | 170 | 30.8 |
18 | 130 | null |