Skip to content

Commit 4ffb4ab

Browse files
lassebenniLasse Benningaclaude
authored
Fix PostgreSQL type casting issues in Week 9 solutions (#32)
* fix(data-track/week-9): clarify validation expectations, deterministic sample, assignment cast note Polish from a Week 9 exercise review (all solutions live-verified against the shared Azure Postgres: Manhattan top, 0 NULL pickups, 189 duplicate groups, 0 orphans, fact view 56,369 = 56,551 - 182 negatives). - Ex1: add ORDER BY pickup_datetime before LIMIT 5 so the sample is stable between runs (a bare LIMIT returns an arbitrary 5 rows). - Ex5: tell students 5a returns 0 and 5c returns empty BY DESIGN (pickup IDs are complete; orphans do not exist on this load). A 0 is the check passing, not a mistake. Prevents the "did I break it?" confusion. - Ex6: note the practice view is scaled down; the assignment's vw_fact_trips also casts pickup_datetime::TIMESTAMP. Flag it so students do not under-build the assignment deliverable. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * Fix double precision to numeric type casting issue for ROUND() in week 9 exercise solutions --------- Co-authored-by: Lasse Benninga <devops.pipeline@example.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 81016a8 commit 4ffb4ab

3 files changed

Lines changed: 3 additions & 3 deletions

File tree

data-track/week-9/exercise_2/solutions/exercise.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
SELECT
44
z.borough,
55
COUNT(*) AS total_trips, -- WHY COUNT(*): counts every row in the group, which is one row per trip, so this is the trip count per borough
6-
ROUND(AVG(t.fare_amount), 2) AS avg_fare -- WHY ROUND: AVG returns many decimal places; rounding to 2 keeps the fare readable as currency
6+
ROUND(AVG(t.fare_amount)::numeric, 2) AS avg_fare -- WHY ROUND: AVG returns many decimal places; rounding to 2 keeps the fare readable as currency
77
FROM nyc_taxi.raw_trips t
88
INNER JOIN nyc_taxi.raw_zones z
99
ON t.pickup_location_id = z.location_id

data-track/week-9/exercise_4/solutions/exercise.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ joined AS ( -- WHY second CTE: names the "join" step; it read
1515
)
1616
SELECT
1717
borough,
18-
ROUND(AVG(fare_amount), 2) AS avg_fare -- WHY final SELECT only aggregates: the filtering and joining are already done, so this step does one thing
18+
ROUND(AVG(fare_amount)::numeric, 2) AS avg_fare -- WHY final SELECT only aggregates: the filtering and joining are already done, so this step does one thing
1919
FROM joined
2020
GROUP BY borough
2121
ORDER BY avg_fare DESC;

data-track/week-9/exercise_6/solutions/exercise.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ WHERE fare_amount >= 0; -- WHY filter in the view: the cleaning rule (no n
1717
-- 6b. Highest total fare revenue by borough
1818
SELECT
1919
d.borough,
20-
ROUND(SUM(f.fare_amount), 2) AS total_revenue -- WHY SUM: revenue is the total of all fares in the borough, not an average
20+
ROUND(SUM(f.fare_amount)::numeric, 2) AS total_revenue -- WHY SUM: revenue is the total of all fares in the borough, not an average
2121
FROM vw_fact_trips f
2222
INNER JOIN vw_dim_zones d -- WHY join to the dim view: borough names live in the dimension, not the fact, so we join to get the breakdown label
2323
ON f.pickup_location_id = d.location_id

0 commit comments

Comments
 (0)