Last active
August 29, 2015 14:05
-
-
Save zhangxu/6f8123cacb7c5105f977 to your computer and use it in GitHub Desktop.
PostgreSQL `With` Clause
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
with parcel_ids as (select id from parcels where ranch_id = 57), | |
zone_ids as (select id from zones where parcel_id in (select id from parcel_ids)) | |
select extract(month from date) as month, category, sub_category, count(*) from events where (area_type = 'parcel' and area_id in (select id from parcel_ids)) or (area_type = 'zone' and area_id in (select id from zone_ids)) | |
group by extract(month from date), category, sub_category; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment