From 0aeec175acf93fa86298ca3bd787c20d7da647dc Mon Sep 17 00:00:00 2001 From: philipp Date: Fri, 5 Jan 2024 20:08:13 +0100 Subject: [PATCH] show guests km --- src/model/stat.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/model/stat.rs b/src/model/stat.rs index b97a09b..4009670 100644 --- a/src/model/stat.rs +++ b/src/model/stat.rs @@ -58,11 +58,25 @@ WHERE l.distance_in_km IS NOT NULL AND l.arrival LIKE '{year}-%' AND b.name != ' .fetch_one(db) .await .unwrap() - .get::(0); + .get::(0) as i32; + + let rowed_km_guests = sqlx::query(&format!( + " +SELECT CAST(SUM(l.distance_in_km) AS INTEGER) AS rowed_km +FROM user u +INNER JOIN rower r ON u.id = r.rower_id +INNER JOIN logbook l ON r.logbook_id = l.id +WHERE u.is_guest = 1 AND l.distance_in_km IS NOT NULL AND l.arrival LIKE '{year}-%'; +" + )) + .fetch_one(db) + .await + .unwrap() + .get::(0) as i32; Stat { name: "Gäste".into(), - rowed_km: rowed_km as i32, + rowed_km: rowed_km + rowed_km_guests, } } -- 2.45.2