gtfs/sql/rts-trps-cnt.sql

9 lines
626 B
SQL

-- 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;