From b3041d9ca769ec2927dd08911e8cb8062f38129d Mon Sep 17 00:00:00 2001 From: philipp Date: Sat, 6 Apr 2024 19:56:06 +0200 Subject: [PATCH 1/2] also show boats w/o any km --- src/model/stat.rs | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/model/stat.rs b/src/model/stat.rs index baa05aa..7199ce8 100644 --- a/src/model/stat.rs +++ b/src/model/stat.rs @@ -27,23 +27,23 @@ impl BoatStat { let rows = sqlx::query( " - SELECT - boat.id, - location.name AS location, - CAST(strftime('%Y', arrival) AS INTEGER) AS year, - CAST(SUM(distance_in_km) AS INTEGER) AS rowed_km - FROM - logbook - INNER JOIN - boat ON boat.id = logbook.boat_id - INNER JOIN - location ON boat.location_id = location.id - WHERE - boat.name != 'Externes Boot' - GROUP BY - boat_id, year - ORDER BY - boat.name, year DESC; +SELECT + boat.id, + location.name AS location, + CAST(strftime('%Y', COALESCE(arrival, 'now')) AS INTEGER) AS year, + CAST(SUM(COALESCE(distance_in_km, 0)) AS INTEGER) AS rowed_km +FROM + boat +LEFT JOIN + logbook ON boat.id = logbook.boat_id AND logbook.arrival IS NOT NULL +LEFT JOIN + location ON boat.location_id = location.id +WHERE + boat.name != 'Externes Boot' +GROUP BY + boat.id, year +ORDER BY + boat.name, year DESC; ", ) .fetch_all(db) From 37fcdb81bcc6c773aa4d2dcb5a8adbd0b5428c5b Mon Sep 17 00:00:00 2001 From: philipp Date: Sat, 6 Apr 2024 19:57:42 +0200 Subject: [PATCH 2/2] remove unnecessary if --- src/model/stat.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/model/stat.rs b/src/model/stat.rs index 7199ce8..10384b9 100644 --- a/src/model/stat.rs +++ b/src/model/stat.rs @@ -30,7 +30,7 @@ impl BoatStat { SELECT boat.id, location.name AS location, - CAST(strftime('%Y', COALESCE(arrival, 'now')) AS INTEGER) AS year, + CAST(strftime('%Y', arrival) AS INTEGER) AS year, CAST(SUM(COALESCE(distance_in_km, 0)) AS INTEGER) AS rowed_km FROM boat