Skip to content

Commit

Permalink
Add modified field to demographicsParents
Browse files Browse the repository at this point in the history
  • Loading branch information
bbimber committed Sep 27, 2024
1 parent 93e150a commit d7af0c7
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions PMR/resources/queries/study/demographicsParents.sql
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,27 @@ SELECT

(CASE WHEN p3.parent IS NOT NULL THEN 1 ELSE 0 END +
CASE WHEN coalesce(p2.parent, b.dam) IS NOT NULL THEN 1 ELSE 0 END +
CASE WHEN coalesce(p1.parent, b.sire) IS NOT NULL THEN 1 ELSE 0 END) as numParents
CASE WHEN coalesce(p1.parent, b.sire) IS NOT NULL THEN 1 ELSE 0 END) as numParents,
greatest(d.modified, p1.modified, p2.modified, p3.modified, b.modified) as modified

FROM study.demographics d

LEFT JOIN (
select p1.id, min(p1.method) as method, max(p1.parent) as parent
select p1.id, min(p1.method) as method, max(p1.parent) as parent, max(p1.modified) as modified
FROM study.parentage p1
WHERE (p1.method = 'Genetic' OR p1.method = 'Provisional Genetic') AND p1.relationship = 'Sire' AND p1.enddate IS NULL
GROUP BY p1.Id
) p1 ON (d.Id = p1.id)

LEFT JOIN (
select p2.id, min(p2.method) as method, max(p2.parent) as parent
select p2.id, min(p2.method) as method, max(p2.parent) as parent, max(p2.modified) as modified
FROM study.parentage p2
WHERE (p2.method = 'Genetic' OR p2.method = 'Provisional Genetic') AND p2.relationship = 'Dam' AND p2.enddate IS NULL
GROUP BY p2.Id
) p2 ON (d.Id = p2.id)

LEFT JOIN (
select p3.id, min(p3.method) as method, max(p3.parent) as parent
select p3.id, min(p3.method) as method, max(p3.parent) as parent, max(p3.modified) as modified
FROM study.parentage p3
WHERE p3.relationship = 'Foster Dam' AND p3.enddate IS NULL
GROUP BY p3.Id
Expand Down

0 comments on commit d7af0c7

Please sign in to comment.