Last active
August 29, 2015 14:21
-
-
Save edivandecastro/950f0f05d8b87658cb98 to your computer and use it in GitHub Desktop.
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
-- get all latest the finished progresses of all individuals | |
SELECT * | |
FROM progresses pr | |
WHERE id = ( | |
SELECT id | |
FROM progresses p | |
WHERE p.individual_id = pr.individual_id AND p.procedure_id = pr.procedure_id AND p.finished | |
ORDER BY p.created_at DESC LIMIT 1 ) | |
ORDER BY pr.created_at DESC; | |
-- get all latest the finished progresses of one individual | |
SELECT * | |
FROM progresses pr | |
WHERE pr.id = ( | |
SELECT p.id | |
FROM progresses p | |
INNER JOIN procedures pc ON pc.individual_id = 1 AND p.procedure_id = pc.id | |
WHERE p.individual_id = 1 AND p.procedure_id = pr.procedure_id AND p.finished | |
ORDER BY p.created_at DESC LIMIT 1 ) | |
ORDER BY pr.created_at DESC; | |
-- get all latest the not finished progresses of all individuals | |
SELECT * | |
FROM progresses pr | |
WHERE id = ( | |
SELECT id | |
FROM progresses p | |
WHERE p.individual_id = pr.individual_id AND p.procedure_id = pr.procedure_id AND NOT p.finished | |
ORDER BY p.created_at DESC LIMIT 1 ) | |
ORDER BY pr.created_at DESC; | |
-- get all latest the not finished progresses of one individual | |
SELECT * | |
FROM progresses pr | |
WHERE id = ( | |
SELECT id | |
FROM progresses p | |
WHERE p.individual_id = 1 AND p.procedure_id = pr.procedure_id AND NOT p.finished | |
ORDER BY p.created_at DESC LIMIT 1 ) | |
ORDER BY pr.created_at DESC; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://gist.github.com/edivandecastro/46db955106c51788addd