SELECT 
 b.*
-- count(*) 2494
FROM beneficiaire b 
INNER JOIN adherent a ON a.id=b.idAdherent
INNER JOIN police p ON p.id=b.IdPolice
AND p.codeGcAssureur='GNA'
AND CASE WHEN b.sorti = "1" THEN b.dateSortie >= '2022-12-31'  ELSE b.dateSortie IS NULL END   
