This one is quite challenging to me ...
I have a table of persons, a table of activities and a table in between to store the registrations (just holding person_id, activity_id and time_of_registration). The query underneath counts the number of persons who registered for acitivity1 and activity2 (well, in fact of the types of activities, but that is info is not necessary).
However, now I would like to count "the number of persons who registered FIRST for activity1 and THEN for activity2 (so where time_of_registration1 < time_of_registration2). How could I do this ?
$sql = "select count(*) from persons
where person_id in
(select person_id
from registrations
where activity_id in
(select activity_id
from activities
where activitytype='$type1->activitytype_id' AND
fiscal_year='$cur_year'))
AND
person_id in (select person_id
from registrations
where activity_id in
(select activity_id
from activities
where activitytype='$type2->activitytype_id' AND
fiscal_year='$cur_year'))";