Skip to content

Instantly share code, notes, and snippets.

@jenikm
Created July 31, 2013 17:24
Show Gist options
  • Save jenikm/6124130 to your computer and use it in GitHub Desktop.
Save jenikm/6124130 to your computer and use it in GitHub Desktop.
Average of weight WITH price
select id, category, price, actual_weight , round(avg(actual_weight) over(partition by category rows between 2 preceding and 2 following),2),sum(actual_weight) over(partition by category rows between 2 preceding and 2 following), status from (select id, primary_category_id_reference as category, round(price_cents/100.0, 2) as price, weight as actual_weight, status from order_items where status between 5 and 8 and created_at > '2013-04-01' order by category, price_cents desc limit 1000) a;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment