Created
December 11, 2016 18:26
-
-
Save hampelm/19942e275e8c0bd1e695b4837282e279 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| with prices as ( | |
| select new.name, new.units, old_price, new_price, new_price::float - old_price::float as price_diff, (old_price %2B new_price)/2.0 as price_avg | |
| from ( | |
| select name, units, price as old_price | |
| from coop where date = current_date - '7 days'::interval | |
| ) old | |
| join ( | |
| select name, units, price as new_price | |
| from coop where date = (select max(date) from coop) | |
| ) new | |
| on old.name = new.name and old.units = new.units | |
| ) | |
| select *, price_diff/price_avg * 100 as pcg_change | |
| from prices order by price_diff; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment