fix stat query
This commit is contained in:
parent
93c6fd2ce7
commit
98578abbe6
@ -13,21 +13,11 @@ impl Stat {
|
||||
//TODO: switch to query! macro again (once upgraded to sqlite 3.42 on server)
|
||||
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
|
||||
INNER JOIN (
|
||||
SELECT r.rower_id AS user_id, l.distance_in_km
|
||||
FROM logbook l
|
||||
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
|
||||
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
|
||||
GROUP BY u.name
|
||||
ORDER BY rowed_km DESC;
|
||||
",
|
||||
|
Loading…
Reference in New Issue
Block a user