Skip to content

Instantly share code, notes, and snippets.

@MarioCares
Last active July 24, 2018 19:58
Show Gist options
  • Save MarioCares/34d11df5d624ffcf9bc088b669ff1bd4 to your computer and use it in GitHub Desktop.
Save MarioCares/34d11df5d624ffcf9bc088b669ff1bd4 to your computer and use it in GitHub Desktop.
Cantidad migrantes y cantidad atenciones a migrantes por año
-- CANTIDAD MIGRANTES
select nac.NOMBRE, count(*) as 'Cantidad Migrantes'
from USP_USUARIO_APS as usp
inner join NAC_NACIONALIDAD as nac on nac.id = usp.NAC_ID
where NAC_ID > 1 and usp.NOD_ID in (225, 226, 227, 2957) and year(usp.FECHA_INSCRIPCION) = 2018
group by nac.nombre
order by count(*) desc;
-- CANTIDAD ATENCIONES A MIGRANTES
select nac.nombre, count(*) as 'Cantidad Atenciones'
from ATEN_ATENCION as aten
inner join USP_USUARIO_APS as usp on usp.ID = aten.USP_ID
inner join NAC_NACIONALIDAD as nac on nac.ID = usp.NAC_ID
where usp.NAC_ID > 1 and year(aten.FECHA_HORA_INICIO) = 2018
and aten.NOD_ID in (225, 226, 227, 2957)
group by nac.NOMBRE
order by count(*) desc;
/* CANTIDAD MIGRANTES POR SEXO (nacionalidad despreciable)
N.P: EN el caso que un progre lo lea, "despreciable" porque en éste caso da lo mismo la nacionalidad */
select count(*) as 'Inmigrantes', sexo.DESCRIPCION as sexo, nodo.DESCRIPCION
from USP_USUARIO_APS as usp
inner join NOD_NODO as nodo on nodo.ID = usp.NOD_ID
inner join HL7_0001_U as sexo on sexo.ID = usp.HL7_0001_U_ID
where usp.NAC_ID > 1 and usp.NOD_ID = 2957 and year(usp.FECHA_INSCRIPCION) = 2018
group by sexo.DESCRIPCION, nodo.DESCRIPCION
order by count(*) desc;
-- MIGRANTES EMBARAZADAS
select nac.NOMBRE as 'Nacionalidad', count(*) as 'Inmigrantes'
from CIT_CITA as cita
inner join USP_USUARIO_APS as usp on usp.ID = cita.USP_ID
inner join NAC_NACIONALIDAD as nac on nac.ID = usp.NAC_ID
where cita.ES_EMBARAZADA = 1 and year(cita.FECHA_HORA_INICIO) = 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment