Last active
December 6, 2019 16:24
-
-
Save shivrajbadu/d5918bf2c57caf0dede82d0096d44c95 to your computer and use it in GitHub Desktop.
this is the simple query which return all new visited patients on filter date
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| select patient_histories.*, patients.* from patients join patient_histories on patient_histories.id = ( | |
| select id from patient_histories | |
| where patient_histories.patient_id = patients.id | |
| order by patient_histories.id asc | |
| limit 1 | |
| ) | |
| /*where patients.gender="female"*/ | |
| /*and patient_histories.year="2076" and patient_histories.month="8" and patient_histories.day="19"*/ | |
| /*https://www.periscopedata.com/blog/4-ways-to-join-only-the-first-row-in-sql)*/ | |
| def self.qry | |
| year = "2076" | |
| month = "4" | |
| day = "1" | |
| p=[] | |
| patients = Patient.all | |
| patients.each do |patient| | |
| first_patient_history = patient.patient_histories.first | |
| p << patient if first_patient_history.year == year && first_patient_history.month==month && first_patient_history.day==day | |
| end | |
| puts p.size | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment