From 1c020da84f334b529adfcbc553341647d2d5b4bd Mon Sep 17 00:00:00 2001 From: philipp Date: Fri, 5 Jan 2024 20:37:40 +0100 Subject: [PATCH] fix stat --- src/model/stat.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/model/stat.rs b/src/model/stat.rs index 4009670..dcf66b8 100644 --- a/src/model/stat.rs +++ b/src/model/stat.rs @@ -66,7 +66,9 @@ 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}-%'; +INNER JOIN user_role ur ON u.id = ur.user_id +INNER JOIN role ro ON ur.role_id = ro.id +WHERE ro.name = 'scheckbuch' AND l.distance_in_km IS NOT NULL AND l.arrival LIKE '{year}-%'; " )) .fetch_one(db) @@ -89,10 +91,17 @@ WHERE u.is_guest = 1 AND l.distance_in_km IS NOT NULL AND l.arrival LIKE '{year} sqlx::query(&format!( " SELECT u.name, CAST(SUM(l.distance_in_km) AS INTEGER) AS rowed_km -FROM user u +FROM ( + SELECT * FROM user + WHERE id NOT IN ( + SELECT user_id FROM user_role + JOIN role ON user_role.role_id = role.id + WHERE role.name = 'scheckbuch' + ) +) 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 = 0 AND l.distance_in_km IS NOT NULL AND l.arrival LIKE '{year}-%' +WHERE l.distance_in_km IS NOT NULL AND l.arrival LIKE '{year}-%' GROUP BY u.name ORDER BY rowed_km DESC; "