On Tue, Jan 15, 2019 at 9:52 AM Alexander Farber <alexander.farber@gmail.com> wrote: >> So calculate the average somewhere else, put the result in a column, >> and then reference that column in the SET clause. > > do you suggest to add a second CTE?
That would qualify as "somewhere else" - as would a simple subquery in FROM.
they escaped my mind for some reason! :-)
WITH diffs AS (
SELECT
gid,
uid,
played - LAG(played) OVER(PARTITION BY gid ORDER BY played) AS diff