update window func

This commit is contained in:
anton
2026-01-17 11:14:34 +03:00
parent d7435d1e10
commit f98bc2632b
@@ -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;
*/
with t as(
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;
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;