From 0231d2bd21f47ff3e67db8a051e5684470c0eac7 Mon Sep 17 00:00:00 2001 From: philipp Date: Mon, 12 Feb 2024 20:09:30 +0100 Subject: [PATCH] only show donauLinz user in stats, otherwise count as guest --- src/model/stat.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/model/stat.rs b/src/model/stat.rs index f91cb29..7af471a 100644 --- a/src/model/stat.rs +++ b/src/model/stat.rs @@ -62,13 +62,18 @@ WHERE l.distance_in_km IS NOT NULL AND l.arrival LIKE '{year}-%' AND b.name != ' let rowed_km_guests = sqlx::query(&format!( " -SELECT CAST(SUM(l.distance_in_km) AS INTEGER) AS rowed_km +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 -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}-%'; +WHERE u.id NOT IN ( + SELECT ur.user_id + FROM user_role ur + INNER JOIN role ro ON ur.role_id = ro.id + WHERE ro.name = 'Donau Linz' +) +AND l.distance_in_km IS NOT NULL +AND l.arrival LIKE '{year}-%'; " )) .fetch_one(db) @@ -93,10 +98,10 @@ WHERE ro.name = 'scheckbuch' AND l.distance_in_km IS NOT NULL AND l.arrival LIKE SELECT u.name, CAST(SUM(l.distance_in_km) AS INTEGER) AS rowed_km FROM ( SELECT * FROM user - WHERE id NOT IN ( + WHERE id IN ( SELECT user_id FROM user_role JOIN role ON user_role.role_id = role.id - WHERE role.name = 'scheckbuch' + WHERE role.name = 'Donau Linz' ) ) u INNER JOIN rower r ON u.id = r.rower_id