Created
September 18, 2014 22:19
-
-
Save gaygenius/1e57d165a77cae5df2cf to your computer and use it in GitHub Desktop.
Query to pick the "starting OES id" for ingress from MySQL
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
WITH | |
config_oes_ids AS ( | |
SELECT (config->>'precedingOESId')::integer AS id, organization_id | |
FROM connections | |
GROUP BY organization_id | |
), | |
max_deliv_oes_ids AS ( | |
SELECT max(id) as id, organization_id | |
FROM deliverables | |
GROUP BY organization_id | |
), | |
mashup AS ( | |
SELECT COALESCE(md.id, cc.id) AS chosen_oes_id, md.id AS md, cc.id AS cc, c.organization_id | |
FROM connections c | |
LEFT JOIN config_oes_ids AS cc USING (organization_id) | |
LEFT JOIN max_deliv_oes_ids AS md USING (organization_id) | |
WHERE (c.config->>'active') = 'true' | |
) | |
SELECT * FROM mashup | |
WHERE chosen_oes_id IS NOT NULL | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment