-- AUDITORIA DE NATURALEZA DE LOTE (SNC)
SELECT 
    tipo_cuenta,
    count(*) as total_registros,
    count(NULLIF(padron::text, '')) as con_padron,
    count(NULLIF(ccatastral, '')) as con_catastro,
    count(CASE WHEN (padron IS NULL OR padron::text = '') AND (ccatastral IS NOT NULL AND ccatastral != '') THEN 1 END) as solo_catastro_prob_urbano,
    count(CASE WHEN (padron IS NOT NULL AND padron::text != '') AND (ccatastral IS NULL OR ccatastral = '') THEN 1 END) as solo_padron_prob_rural
FROM public.snc_raw_lotes_activos 
WHERE dpto = 'F' AND dist = 1
GROUP BY tipo_cuenta;
