Skip to content

Instantly share code, notes, and snippets.

@daohodac
Created May 29, 2013 15:09
Show Gist options
  • Select an option

  • Save daohodac/5671039 to your computer and use it in GitHub Desktop.

Select an option

Save daohodac/5671039 to your computer and use it in GitHub Desktop.
get the last components which belongs to a holder that is in the five last by category
select * from cl_component
where holder_id in(
SELECT r1.id
FROM cl_checklist r1
LEFT OUTER JOIN cl_checklist r2
ON (r1.aircraftcid = r2.aircraftcid AND r1.checklistcid = r2.checklistcid AND r1.created < r2.created)
WHERE r1.dtype='Report' AND r1.checklistcid='ef0fd241-9a6c-43f0-8074-4ca310108ff5' AND r1.aircraftreg='F-GFKF'
GROUP BY r1.id, r1.serverLastUpdate, r1.created
HAVING COUNT(*) < 5
ORDER BY r1.id DESC
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment