Created
February 9, 2023 03:43
-
-
Save cliftonlabrum/41a6747093f37dfab98db3c132214720 to your computer and use it in GitHub Desktop.
Query Your Face
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
IFNULL(SUM(duration), 0) AS duration, | |
IFNULL(SUM(landingsDay), 0) AS landingsDay, | |
IFNULL(SUM(landingsNight), 0) AS landingsNight | |
FROM ( | |
SELECT | |
flight.id, | |
MAX(duration) AS duration, | |
MAX(landingsDay) AS landingsDay, | |
MAX(landingsNight) AS landingsNight | |
FROM flight | |
LEFT JOIN aircraft ON flight.aircraftId = aircraft.id | |
LEFT JOIN aircraftCategory ON aircraftCategory.id = aircraft.aircraftCategoryId | |
LEFT JOIN value ON value.flightId = flight.id OR value.aircraftId = flight.aircraftId | |
LEFT JOIN field ON field.id = value.fieldId | |
WHERE | |
flight.trashed = 0 | |
GROUP BY | |
flight.id | |
HAVING | |
1 = 1 AND MAX(CASE WHEN field.id = "Day" THEN value.time > 0 OR value.boolean = 1 END) > 0 | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment