Judging from your numbers, you may be looking for this:
SELECT *, round(ct::numeric/first_value(ct) OVER (ORDER BY day), 4) AS pct
FROM tbl;
"A percentage for each row, calculated as ct
divided by ct
of the first row as defined by the smallest day
number."
The key is the window function first_value()
.