From ea67f7e49a56db71e533fadfb3474a6b83288874 Mon Sep 17 00:00:00 2001 From: Marc Cenac Date: Sun, 28 Jan 2018 08:26:53 -0600 Subject: [PATCH] adding db view for neighborhood specific summary --- setup/install.sh | 1 + views/open_tickets_neighborhood_summary.sql | 37 +++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 views/open_tickets_neighborhood_summary.sql diff --git a/setup/install.sh b/setup/install.sh index 6d8bddb..1ae77a0 100755 --- a/setup/install.sh +++ b/setup/install.sh @@ -16,3 +16,4 @@ psql -U $NOLA311_DB_USER -d $NOLA311_DB_NAME -h $NOLA311_DB_HOST -p $NOLA311_DB_ psql -U $NOLA311_DB_USER -d $NOLA311_DB_NAME -h $NOLA311_DB_HOST -p $NOLA311_DB_PORT -f views/closed_tickets_stats.sql -q psql -U $NOLA311_DB_USER -d $NOLA311_DB_NAME -h $NOLA311_DB_HOST -p $NOLA311_DB_PORT -f views/call_records_for_review.sql -q psql -U $NOLA311_DB_USER -d $NOLA311_DB_NAME -h $NOLA311_DB_HOST -p $NOLA311_DB_PORT -f views/call_records_with_call_for_details.sql -q +psql -U $NOLA311_DB_USER -d $NOLA311_DB_NAME -h $NOLA311_DB_HOST -p $NOLA311_DB_PORT -f views/open_tickets_neighborhood_summary.sql -q diff --git a/views/open_tickets_neighborhood_summary.sql b/views/open_tickets_neighborhood_summary.sql new file mode 100644 index 0000000..8cf11ed --- /dev/null +++ b/views/open_tickets_neighborhood_summary.sql @@ -0,0 +1,37 @@ +set search_path to 'nola311'; + +drop view if exists nola311.open_tickets_neighborhood_summary; +create view nola311.open_tickets_neighborhood_summary as ( + with + open_tickets as ( + select + neighborhood_district, + issue_type, + extract(year from ticket_created_date_time) as year_created, + extract(month from ticket_created_date_time) as month_created, + justify_interval(age(ticket_created_date_time)) as time_open + from nola311.calls + where ticket_status = 'Open' + ), + ticket_stats as ( + select + neighborhood_district, + issue_type, + year_created, + month_created, + count(*) as number_open + from open_tickets + group by neighborhood_district, issue_type, year_created, month_created + ) + select + issue_type, + neighborhood_district, + count(*) as num_issues + from ticket_stats + group by neighborhood_district, issue_type +); + +comment on view nola311.open_tickets_neighborhood_summary is 'A summary of the total number of open tickets by issue type for each neighborhood'; + +grant all on nola311.open_tickets_neighborhood_summary to nola311; +