Consider this:
SELECT
review.clicker_id,
sum(review.done - review.due) as timespent,
PERCENTILE_DISC(0.5) WITHIN GROUP(ORDER BY timespent ASC) as median
FROM review WHERE monologue_id=7142 GROUP BY clicker_id ORDER BY timespent ASC;
I'm trying to get the median value for sum(review.done - review.due)
(a time interval.) But, obviously, I'm not allowed to do it this way:
Error in query: ERROR: column "timespent" does not exist LINE 4:
PERCENTILE_DISC(0.5) WITHIN GROUP(ORDER BY time ASC) as m...
How am I supposed to do this?