fix stat query

This commit is contained in:
philipp 2023-10-30 15:31:12 +01:00
parent 93c6fd2ce7
commit 98578abbe6

View File

@ -13,21 +13,11 @@ impl Stat {
//TODO: switch to query! macro again (once upgraded to sqlite 3.42 on server) //TODO: switch to query! macro again (once upgraded to sqlite 3.42 on server)
sqlx::query( sqlx::query(
" "
SELECT u.name, CAST(SUM(sub.distance_in_km) AS INTEGER) AS rowed_km SELECT u.name, CAST(SUM(l.distance_in_km) AS INTEGER) AS rowed_km
FROM user u FROM user u
INNER JOIN ( INNER JOIN rower r ON u.id = r.rower_id
SELECT r.rower_id AS user_id, l.distance_in_km INNER JOIN logbook l ON r.logbook_id = l.id
FROM logbook l WHERE u.is_guest = 0 AND l.distance_in_km IS NOT NULL
INNER JOIN rower r ON l.id = r.logbook_id
WHERE l.distance_in_km IS NOT NULL
UNION ALL
SELECT l.shipmaster AS user_id, l.distance_in_km
FROM logbook l
WHERE l.distance_in_km IS NOT NULL
) sub ON u.id = sub.user_id
WHERE u.is_guest = false
GROUP BY u.name GROUP BY u.name
ORDER BY rowed_km DESC; ORDER BY rowed_km DESC;
", ",