From f98bc2632b14793532355a58c41794e4fc4ec580 Mon Sep 17 00:00:00 2001 From: anton Date: Sat, 17 Jan 2026 11:14:34 +0300 Subject: [PATCH] update window func --- .../window functions/win_func_tasks.sql | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/avysokih/postgresql/window functions/win_func_tasks.sql b/avysokih/postgresql/window functions/win_func_tasks.sql index f3a3e5d..87a4388 100644 --- a/avysokih/postgresql/window functions/win_func_tasks.sql +++ b/avysokih/postgresql/window functions/win_func_tasks.sql @@ -44,9 +44,13 @@ order by category; (`price - next_price`) */ -select name, category, price, lead(price) over(partition by category order by price) as next_price, -price - lead(price) over(partition by category order by price) as diff -from products_extended; +with t as( +select name, category, price, +lead(price) over (partition by category order by price) as next_price +from products_extended) +select name, category, price, next_price, +price - next_price as diff +from t order by category; /* Задача 3: @@ -71,10 +75,12 @@ from products_extended; */ -select category, name, price, -round(avg(price) over (partition by category), 1) as avg_price, -price > avg(price) over (partition by category) as is_above_avg -from products_extended; - +with t as( +select category, name, price, +round(avg(price) over (partition by category), 1) as avg_price +from products_extended) +select category, name, price, avg_price, +price > avg_price as is_above_avg +from t order by category;