-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#42 find total obs for each link_dir
- Loading branch information
jovenc
committed
Jan 17, 2020
1 parent
561c160
commit 5096fce
Showing
1 changed file
with
24 additions
and
0 deletions.
There are no files selected for viewing
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
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 |