Skip to content

Instantly share code, notes, and snippets.

@userrails
Created December 6, 2019 12:04
Show Gist options
  • Save userrails/db529388ba1e2d4da9e145acbea3aab4 to your computer and use it in GitHub Desktop.
Save userrails/db529388ba1e2d4da9e145acbea3aab4 to your computer and use it in GitHub Desktop.
DROP TEMPORARY TABLE IF EXISTS patient_visits;
CREATE TEMPORARY TABLE patient_visits LIKE patients;
INSERT INTO patient_visits
SELECT *
FROM patients
WHERE id
IN (
SELECT patient_id
FROM patient_histories
GROUP BY patient_id
HAVING COUNT(patient_id) = 1
);
select * from patient_visits join patient_histories
on patient_visits.id = patient_histories.patient_id
where patient_histories.year="2076"
and patient_histories.month="8"
and patient_histories.day="19"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment