Skip to content

Commit d7af0c7

Browse files
committed
Add modified field to demographicsParents
1 parent 93e150a commit d7af0c7

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

PMR/resources/queries/study/demographicsParents.sql

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,26 +34,27 @@ SELECT
3434

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

3940
FROM study.demographics d
4041

4142
LEFT JOIN (
42-
select p1.id, min(p1.method) as method, max(p1.parent) as parent
43+
select p1.id, min(p1.method) as method, max(p1.parent) as parent, max(p1.modified) as modified
4344
FROM study.parentage p1
4445
WHERE (p1.method = 'Genetic' OR p1.method = 'Provisional Genetic') AND p1.relationship = 'Sire' AND p1.enddate IS NULL
4546
GROUP BY p1.Id
4647
) p1 ON (d.Id = p1.id)
4748

4849
LEFT JOIN (
49-
select p2.id, min(p2.method) as method, max(p2.parent) as parent
50+
select p2.id, min(p2.method) as method, max(p2.parent) as parent, max(p2.modified) as modified
5051
FROM study.parentage p2
5152
WHERE (p2.method = 'Genetic' OR p2.method = 'Provisional Genetic') AND p2.relationship = 'Dam' AND p2.enddate IS NULL
5253
GROUP BY p2.Id
5354
) p2 ON (d.Id = p2.id)
5455

5556
LEFT JOIN (
56-
select p3.id, min(p3.method) as method, max(p3.parent) as parent
57+
select p3.id, min(p3.method) as method, max(p3.parent) as parent, max(p3.modified) as modified
5758
FROM study.parentage p3
5859
WHERE p3.relationship = 'Foster Dam' AND p3.enddate IS NULL
5960
GROUP BY p3.Id

0 commit comments

Comments
 (0)