feat: add sql/rts-stps-trps-cnt.sql

This commit is contained in:
dancingCycle 2024-01-03 18:31:40 +01:00
parent 02ac54ea2b
commit 673b5ab9e6
7 changed files with 38 additions and 3 deletions

View File

@ -5,4 +5,4 @@ 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;
CREATE OR REPLACE VIEW :schema.vw_join_gncy_rts_trps_stptms_stps AS SELECT stptms.agency_id, stptms.agency_name, stptms.stop_id, stps.stop_name FROM :schema.vw_join_gncy_rts_trps_stptms AS stptms LEFT JOIN :schema.stops AS stps ON stptms.stop_id = stps.stop_id ORDER BY stptms.agency_name, stps.stop_name;

View File

@ -6,4 +6,4 @@ 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;
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 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;

8
sql/rts-cnt.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_rts_cnt CASCADE;
CREATE OR REPLACE VIEW :schema.vw_rts_cnt AS SELECT gncy_rts.agency_id, gncy_rts.agency_name, count(DISTINCT gncy_rts.route_id) AS rts_cnt FROM :schema.vw_join_gncy_rts AS gncy_rts GROUP BY gncy_rts.agency_id, gncy_rts.agency_name ORDER BY rts_cnt ASC;

12
sql/rts-stps-trps-cnt.sql Normal file
View File

@ -0,0 +1,12 @@
-- 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_rts_stps_trps_cnt CASCADE;
CREATE OR REPLACE VIEW :schema.vw_rts_stps_trps_cnt AS SELECT gncy_rts_trps.agency_name, gncy_rts_trps.agency_id, count(DISTINCT gncy_rts_trps.route_id) AS rts_cnt, stps_cnt.stps_cnt, count(DISTINCT gncy_rts_trps.trip_id) AS trps_cnt FROM :schema.vw_join_gncy_rts_trps AS gncy_rts_trps LEFT JOIN :schema.vw_stps_cnt AS stps_cnt ON gncy_rts_trps.agency_id = stps_cnt.agency_id GROUP BY gncy_rts_trps.agency_id, gncy_rts_trps.agency_name, stps_cnt.stps_cnt ORDER BY rts_cnt ASC, trps_cnt ASC, stps_cnt ASC;
-- create table
DROP TABLE IF EXISTS :schema.tbl_rts_stps_trps_cnt CASCADE;
CREATE TABLE IF NOT EXISTS :schema.tbl_rts_stps_trps_cnt AS SELECT * FROM :schema.vw_rts_stps_trps_cnt;

8
sql/rts-trps-cnt.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_rts_trps_cnt CASCADE;
CREATE OR REPLACE VIEW :schema.vw_rts_trps_cnt AS SELECT gncy_rts_trps.agency_name, gncy_rts_trps.agency_id, count(DISTINCT gncy_rts_trps.route_id) AS rts_cnt, count(DISTINCT gncy_rts_trps.trip_id) AS trps_cnt FROM :schema.vw_join_gncy_rts_trps AS gncy_rts_trps GROUP BY gncy_rts_trps.agency_id, gncy_rts_trps.agency_name ORDER BY rts_cnt ASC, trps_cnt ASC;

View File

@ -5,7 +5,6 @@ SET search_path to :schema, public;
-- create table
DROP TABLE IF EXISTS :schema.services CASCADE;
CREATE TABLE IF NOT EXISTS :schema.services
(
feed_index int NOT NULL REFERENCES feed_info (feed_index) ON DELETE CASCADE,

8
sql/stps-cnt.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_stps_cnt CASCADE;
CREATE OR REPLACE VIEW :schema.vw_stps_cnt AS SELECT stps.agency_id, stps.agency_name, count(DISTINCT stps.stop_id) AS stps_cnt FROM :schema.vw_join_gncy_rts_trps_stptms_stps AS stps GROUP BY stps.agency_id, stps.agency_name ORDER BY stps_cnt ASC;