I have table with record of children & i want to get comma separated results in descending order by month but with a breaking condition of status of child in each month. if status is 0 push it to array but if status is 1 then don't push it and break it there and don't check previous months record.
Table
Desired Output:
I have tried it this way which gives me all the months. but i don't know how to break it on status = 1 condition for every child
SELECT name, ARRAY_AGG(month ORDER BY month DESC)
FROM children
GROUP BY name