Skip to content

Instantly share code, notes, and snippets.

@shivrajbadu
Created December 6, 2019 04:21
Show Gist options
  • Select an option

  • Save shivrajbadu/311afd7ac238ec45ed364422403cfb68 to your computer and use it in GitHub Desktop.

Select an option

Save shivrajbadu/311afd7ac238ec45ed364422403cfb68 to your computer and use it in GitHub Desktop.
def self.qry
res = Patient.find_by_sql(%{
select * from (
select
patients.id as id,
patient_histories.year as year,
patient_histories.month as month,
patient_histories.day as day
from patients
join patient_histories
on patients.id=patient_histories.patient_id
where patients.gender="female"
and patient_histories.year = '2076'
group by
patients.id,
patient_histories.year,
patient_histories.month,
patient_histories.day
having count(patient_histories.patient_id) = 1
)t group by id, year, month, day
having count(id) = 1
})
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment