I'm having trouble with a particular Oracle query. I'm trying to write a query to pull the following data.
• “How many students who were previously suspended for reason of "bad behaviour" have since been re-assessed AND the number over 12 years old and under 12 years old”
Three tables I believe I need to work with: person status history (contains REASON, SUSPEND_TO_DATE), person_visit (contains fields like VISIT_DATE) and person (contains fields such as PERSON_ID and BIRTH_DATE).
(PERSON_ID is common across all tables.)
Here was my amateur attempt, I'm still not fully sure of the use of joins & how to work out the over 12/under 12 using only the BIRTH_DATE information is another issue.
select count (*) from person_status_history
inner join person_visit on person_status_history.person_id=person_visit.person_id
inner join person on person_visit.person_id=person.person_id
where person_status_history.reason_code = 85 and person_visit.reasses_appoint_no is not null and person.birth_date < '23-JAN-2000';
In basic pseudo-code I suppose what I need to develop is (very rough!):
SELECT * PERSON_ID WHERE SUSPEND_TO_DATE is NOT NULL AND REASON = "85" AND VISIT_DATE > SUSPEND_TO_DATE and count the number >12 AND < 12.
Can anyone advise?