Skip to content

Commit

Permalink
#42 find total obs for each link_dir
Browse files Browse the repository at this point in the history
  • Loading branch information
jovenc committed Jan 17, 2020
1 parent 561c160 commit 5096fce
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions congestion_data_aggregation/create-mview-linkdir_obs.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
CREATE MATERIALIZED ViEW congestion.linkdir_obs AS

SELECT ROW_NUMBER() OVER (ORDER BY SUM(day_count) DESC) AS priority,
link_dir, SUM(day_count) AS total_count
FROM
(
SELECT link_dir, COUNT(DISTINCT tx::date) AS day_count, (datetime_bin(tx,30))::time AS time_bin
FROM congestion.data_fall2019_5min
INNER JOIN congestion.routing_grid USING (link_dir)
GROUP BY link_dir, time_bin
) a
GROUP BY link_dir


--this query is muchhhh slower
WITH X AS (
SELECT link_dir, COUNT(DISTINCT tx::date) AS day_count, (datetime_bin(tx,30))::time AS time_bin
FROM congestion.data_fall2019_5min
INNER JOIN congestion.segment_link_test USING (link_dir)
GROUP BY link_dir, time_bin
)
SELECT ROW_NUMBER() OVER (ORDER BY SUM(day_count) DESC) AS priority, link_dir, sum(day_count) AS total_count
FROM X
GROUP BY link_dir

0 comments on commit 5096fce

Please sign in to comment.