feat: add sql/trps-cnt.sql

This commit is contained in:
dancingCycle 2024-01-03 18:35:54 +01:00
parent 673b5ab9e6
commit c4f4247421
1 changed files with 8 additions and 0 deletions

8
sql/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.cw_trps_cnt CASCADE;
CREATE OR REPLACE VIEW :schema.cw_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;