Created
July 31, 2013 17:24
-
-
Save jenikm/6124130 to your computer and use it in GitHub Desktop.
Average of weight WITH price
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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