Skip to content

Instantly share code, notes, and snippets.

@cliftonlabrum
Created February 9, 2023 05:26
Show Gist options
  • Save cliftonlabrum/71dd24e3ad581e028d05494a59684d82 to your computer and use it in GitHub Desktop.
Save cliftonlabrum/71dd24e3ad581e028d05494a59684d82 to your computer and use it in GitHub Desktop.
HAVING a Hard Time
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
$whereSearch
$whereYear
${filter.where}
GROUP BY
flight.id
HAVING
${filter.having}
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