Created
February 9, 2023 17:04
-
-
Save cliftonlabrum/1046c8268230ead11a7c7cae6fced81d to your computer and use it in GitHub Desktop.
New WHERE
This file contains 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 | |
date, year, month, day, duration, departure, departureName, destination, destinationName, departureTime, destinationTime, route, landingsDay, landingsNight, distance, remarks, signatureId, | |
flight.id AS id, | |
flight.aircraftId AS aircraftId, | |
flight.trashed AS trashed, | |
aircraft.registration AS aircraftRegistration, | |
aircraft.makeModel AS aircraftMakeModel, | |
aircraftCategory.name AS aircraftCategoryName, | |
field.name, | |
value.time, | |
value.boolean | |
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 | |
AND CASE WHEN field.id IN ('Day') THEN | |
CASE | |
WHEN value.boolean = 1 THEN 1 | |
WHEN value.time > 0 THEN 1 | |
END | |
END | |
GROUP BY | |
flight.id | |
ORDER BY | |
year DESC, month DESC, day DESC, departureTime DESC, flight.modified DESC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment