Можно ли как-то объединить несколько повторяющихся предложений OVER
в Postgres?
Пример со сценарием CASE ... END
:
case
when hhk = lag(hhk) over (order by hhk, product, dt)
and product = lag(product) over (order by hhk, product, dt)
then dt - lag(dt) over (order by hhk, product, dt)
else null
end as delta
Предложение over (order by hhk, product, dt)
повторяется трираз.Я ищу способ как-то сгруппировать их, например, следующий (который, конечно, не работает как таковой):
case
-- here we combine the two conditions into one
when [hhk, product] = lag([hhk, product])
over (order by hhk, product, dt)
-- and here we somehow recall the clause
then dt - lag(dt) over (my_clause)
else null
end as delta