Skip to content

Instantly share code, notes, and snippets.

@jdwyah
Created May 11, 2013 20:43
Show Gist options
  • Save jdwyah/5561373 to your computer and use it in GitHub Desktop.
Save jdwyah/5561373 to your computer and use it in GitHub Desktop.
similarities as (
select distinct
ss.user_id as id,
sum((sr.symptom_severity - coalesce(target.symptom_severity,0)) ^ 2) OVER (PARTITION BY ss.user_id),
count(sr.id) OVER (PARTITION BY ss.user_id) as count
from latest_symptom_surveys ss
join symptom_reports sr on sr.symptom_survey_id = ss.id
left join target on target.symptom_id = sr.symptom_id
join users u on u.id = ss.user_id
where u.disease_id = #{self.disease_id}
and u.id <> #{self.id})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment