update window func
This commit is contained in:
@@ -44,9 +44,13 @@ order by category;
|
|||||||
(`price - next_price`)
|
(`price - next_price`)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
select name, category, price, lead(price) over(partition by category order by price) as next_price,
|
with t as(
|
||||||
price - lead(price) over(partition by category order by price) as diff
|
select name, category, price,
|
||||||
from products_extended;
|
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:
|
Задача 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;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user