feat: add union of trps, stptms and stps

This commit is contained in:
dancingCycle 2024-01-03 13:43:03 +01:00
parent 5b563e7b5e
commit 02ac54ea2b
4 changed files with 33 additions and 0 deletions

View File

@ -0,0 +1,8 @@
-- colon before variable: for a prepared statement using named placeholders, this will be a parameter name of the form :name
CREATE SCHEMA IF NOT EXISTS :schema;
SET search_path to :schema, public;
-- create view
DROP VIEW IF EXISTS :schema.vw_join_gncy_rts_trps_stptms_stps CASCADE;
CREATE OR REPLACE VIEW :schema.vw_join_gncy_rts_trps_stptms_stps AS SELECT gncy_rts_trps_stptms.agency_id, gncy_rts_trps_stptms.agency_name, gncy_rts_trps_stptms.stop_id, stps.stop_name FROM :schema.vw_join_gncy_rts_trps_stptms AS gncy_rts_trps_stptms JOIN :schema.stops AS stps ON gncy_rts_trps_stptms.stop_id = stps.stop_id ORDER BY gncy_rts_trps_stptms.agency_name, stps.stop_name;

View File

@ -0,0 +1,9 @@
-- colon before variable: for a prepared statement using named placeholders, this will be a parameter name of the form :name
CREATE SCHEMA IF NOT EXISTS :schema;
SET search_path to :schema, public;
-- create view
DROP VIEW IF EXISTS :schema.vw_join_gncy_rts_trps_stptms CASCADE;
--CREATE OR REPLACE VIEW :schema.vw_join_gncy_rts_trps_stptms AS SELECT gncy_rts_trps.agency_id, gncy_rts_trps.agency_name, gncy_rts_trps.route_id, gncy_rts_trps.route_short_name, gncy_rts_trps.service_id, gncy_rts_trps.trip_id, gncy_rts_trps.trip_short_name, gncy_rts_trps.trip_headsign, stptms.stop_id FROM :schema.vw_join_gncy_rts_trps AS gncy_rts_trps RIGHT JOIN :schema.stop_times AS stptms ON gncy_rts_trps.trip_id = stptms.trip_id ORDER BY gncy_rts_trps.agency_name, gncy_rts_trps.route_id, gncy_rts_trps.trip_id;
CREATE OR REPLACE VIEW :schema.vw_join_gncy_rts_trps_stptms AS SELECT gncy_rts_trps.agency_id, gncy_rts_trps.agency_name, stptms.stop_id FROM :schema.vw_join_gncy_rts_trps AS gncy_rts_trps RIGHT JOIN :schema.stop_times AS stptms ON gncy_rts_trps.trip_id = stptms.trip_id GROUP BY stptms.stop_id, gncy_rts_trps.agency_id, gncy_rts_trps.agency_name ORDER BY gncy_rts_trps.agency_name;

View File

@ -0,0 +1,8 @@
-- colon before variable: for a prepared statement using named placeholders, this will be a parameter name of the form :name
CREATE SCHEMA IF NOT EXISTS :schema;
SET search_path to :schema, public;
-- create view
DROP VIEW IF EXISTS :schema.vw_stps_count_gncy CASCADE;
CREATE OR REPLACE VIEW :schema.vw_stps_count_gncy AS SELECT stps.agency_id, stps.agency_name, count(DISTINCT stps.stop_id) AS stop_count FROM :schema.vw_join_gncy_rts_trps_stptms_stps AS stps GROUP BY stps.agency_id, stps.agency_name ORDER BY stop_count ASC;

8
sql/vw-stops-lt-0.sql Normal file
View File

@ -0,0 +1,8 @@
-- colon before variable: for a prepared statement using named placeholders, this will be a parameter name of the form :name
CREATE SCHEMA IF NOT EXISTS :schema;
SET search_path to :schema, public;
---create view
DROP VIEW IF EXISTS :schema.vw_stops_lt_0 CASCADE;
CREATE OR REPLACE VIEW :schema.vw_stops_lt_0 AS SELECT * FROM :schema.stops WHERE location_type=0;