I have a table that has the "document number" field, the type of flow (entering or leaving the country), date of birth, and the date the flow occurred.
Knowing that a person can leave or enter several times a year, how can I list those people (by their document number) of legal age (>=21yo) who were out of the country in a specific interval of the year (for example: between May 1, 2021 and August 1, 2021)?
ideally a syntax according to postgresql
EDIT: Info complement
Table: flows
id_flow | doc_number | brth_date | flow_type | flow_date |
---|---|---|---|---|
1 | 123 | 1999-05-01 | in | 2020-06-01 |
2 | 123 | 1999-05-01 | out | 2020-10-30 |
3 | 222 | 1988-01-09 | out | 2021-01-01 |
4 | 180 | 1993-11-15 | out | 2021-06-16 |
5 | 222 | 1988-01-09 | in | 2021-10-30 |
6 | 223 | 2009-09-05 | out | 2020-06-04 |
7 | 223 | 2009-09-05 | in | 2021-12-04 |
where dates are yyy-MM-DD and should return:
doc_number |
---|
123 |
222 |
because these people were out in the whole interval and has legal age.