Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. select project, uri subject_uri, var_patient_uri
  2. from (
  3. select agg.*, detail.uri from (
  4. select 'proms_consent' as project, created, q1.var_patient_uri, q1.var_registration, var_sys_status_label
  5. , var_sys_date_submitted
  6. , row_number() over (partition by q1.var_patient_uri order by var_sys_status, var_sys_date_submitted asc, created desc) from proms_consent.cases q1
  7. join (
  8. select count(1), var_patient_uri, var_moment, var_registration,var_id from proms_consent.cases group by 2,3,4,5 having count(1) > 1
  9. ) q2
  10. on q1.var_patient_uri = q2.var_patient_uri and q2.var_registration = q2.var_registration
  11. ) agg
  12. join proms_consent.cases detail
  13. on agg.var_patient_uri = detail.var_patient_uri
  14. and agg.created = detail.created
  15. where row_number = 1
  16. ) q3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement