SELECT `_ID`, `weight_date`, `weight_start_week`, `weight_end_week`
total_weight, prev_total_weight, lowest_weight, highest_weight,
weight_week,
CASE ...
FROM
(
-- place CTE definition here
SELECT *, ...
ROW_NUMBER() OVER( ORDER BY weight_date DESC) AS RowNum
FROM ...
) t;