3 ms·
I see, it's joining with the lagged weight. Same without CTE: SELECT c.name, c.weight, c.weight - lw.lower_weight AS weight_to_lose FROM cats c JOIN (SEL
by karmakaze 9y ago
I see, it's joining with the lagged weight. Same without CTE:
SELECT c.name, c.weight, c.weight - lw.lower_weight AS weight_to_lose
FROM cats c
JOIN (SELECT weight, lag(weight, 1, weight) over (order by weight)
lower_weight FROM cats
GROUP BY weight
ORDER BY weight) lw ON c.weight = lw.weight
ORDER BY weight