feat: adjust sql/trip-count.sql

This commit is contained in:
dancingCycle 2023-12-21 08:07:36 +01:00
parent 99100386e8
commit 4340a1d7ea
1 changed files with 1 additions and 2 deletions

View File

@ -4,5 +4,4 @@ CREATE SCHEMA IF NOT EXISTS :schema;
SET search_path to :schema, public;
---create view
CREATE OR REPLACE VIEW :schema.vw_trip_count AS
SELECT count (DISTINCT trps.trip_id) AS trip_count, count(DISTINCT trps.route_id) AS route_count, rts.agency_id, gncy.agency_name FROM :schema.trips AS trps LEFT JOIN :schema.routes AS rts ON trps.route_id = rts.route_id LEFT JOIN :schema.agency AS gncy ON rts.agency_id = gncy.agency_id GROUP BY rts.agency_id, gncy.agency_name ORDER BY trip_count DESC, route_count DESC;
CREATE OR REPLACE VIEW :schema.vw_trip_count AS SELECT gncy.agency_name, gncy.agency_id, count(DISTINCT trps.route_id) AS route_count, count(DISTINCT trps.trip_id) AS trip_count FROM :schema.agency AS gncy LEFT JOIN :schema.routes AS rts ON rts.agency_id = gncy.agency_id LEFT JOIN :schema.trips AS trps ON trps.route_id = rts.route_id GROUP BY gncy.agency_id, gncy.agency_name ORDER BY route_count ASC, trip_count ASC;