Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
sum(price) OVER (PARTITION by 0)А SUM(price) OVER() (т.е. пустой OVER) не работает в Постгресе что ли?
SET TIME ZONE 'Europe/Moscow';, например).with september_sales as (
select distinct sku,
sum(price) OVER (PARTITION BY sku) as revenue,
count(1) OVER (PARTITION BY sku) as sales_count,
sum(price) OVER (PARTITION by 0) as sales_total
from invoice_items
where date_part('month',created_at) = 9
)
select sku,
revenue::money,
sales_count,
sales_total::money,
trunc((revenue/sales_total * 100),4) as percentage
from september_sales
select sku,
revenue::money,
sales_count,
sales_total::money,
trunc((revenue/sales_total * 100),4) as percentage
from (
select distinct sku,
sum(price) OVER (PARTITION BY sku) as revenue,
count(1) OVER (PARTITION BY sku) as sales_count,
sum(price) OVER (PARTITION by 0) as sales_total
from invoice_items
where date_part('month',created_at) = 9
) t
Охватывающий SQL в Postgres