Psst.. new poll here.
[email protected] web/email now available. Want one? Go here.
Cannot use outlook/hotmail/live here to register as they blocking our mail servers. #microsoftdeez
Obey the Epel!
Paste
Pasted as Plain Text by registered user vvillacorta ( 3 years ago )
SELECT NUMRUC,
SUM(CASE WHEN ESTADOTRIBUTO = 0 THEN MONTODEUDATRIBUTO ELSE 0 END) MAX_MONTODEUDATRIBUTO,
MAX(NUMTRABAJADORES) MAX_NUMTRABAJADORES ,
CASE WHEN MAX(FECBAJA) IS NULL THEN (CURRENT_DATE - MAX(FECALTA)) /360 ELSE (MAX(FECBAJA) - MAX(FECALTA) ) /360 END ANOS_EMPRESA,
CASE WHEN MAX(FECBAJA) IS NOT NULL THEN (CURRENT_DATE - MAX(FECBAJA)) /360 ELSE 0 END ANOS_DESDE_BAJA,
COUNT(DISTINCT(CASE WHEN ESTADORELE = 0 THEN NUMRUC ELSE NULL END )) CNT_RRLL,
MAX(ESTADOCONTRIBUYENTE) MAX_ESTADOCONTRIBUYENTE ,
MAX(CONDICIONDOMICILIO) MAXCONDICIONDOMICILIO,
MAX(CIIU) CIIU,
MAX(TIPPERSONA) TIPPERSONA,
MAX(FACTURACION) FACTURACION,
MAX(TIENEDIR) TIENEDIR,
MAX(TIENETELEF) TIENETELEF,
MAX(COMERCIOEXTERIOR) COMERCIOEXTERIOR,
MAX(RANGOVENTAS) RANGOVENTAS,
AVG(EDAD) PROMEDIO_EDAD_RRLL,
MAX(EDAD) MAX_EDAD_RRLL, MIN(EDAD) MIN_EDAD_RRLL,
SUM (EST_CIVIL_DIVORCIADO) CNT_RRLL_DIVORCIADO,
SUM (EST_CIVIL_SOLTERO) CNT_RRLL_SOLTERO,
SUM (EST_CIVIL_CASADO) CNT_RRLL_CASADO,
SUM (EST_CIVIL_VIUDO) CNT_RRLL_VIUDO,
SUM(EST_CIVIL_FEMENINO) CNT_GEN_F ,
SUM(EST_CIVIL_MASCULINO) CNT_GEN_M ,
SUM(DON_ORGANOS) CNT_DON_ORGANOS,
SUM(RESIDENCIA_LIMA_CALLAO) CNT_RESIDENCIA_LIMA_CALLAO,
SUM(RESIDENCIA_PROVICNCIA) CNT_RESIDENCIA_PROVICNCIA,
SUM(RESIDENCIA_EXTRANJERA) CNT_RESIDENCIA_EXTRANJERA,
CAST((SUM(RESIDENCIA_LIMA_CALLAO))/COUNT(CODDOCRELE) AS DECIMAL(4,2)) PERCENT_RESIDENCIA_LIMA_CALLAO ,
CAST((SUM(RESIDENCIA_PROVICNCIA))/COUNT(CODDOCRELE) AS DECIMAL(4,2)) PERCENT_RESIDENCIA_PROVICNCIA,
CAST(SUM(RESIDENCIA_EXTRANJERA)/COUNT(CODDOCRELE) AS DECIMAL(4,2)) PERCENT_RESIDENCIA_EXTRANJERA,
CAST(SUM (EST_CIVIL_DIVORCIADO)/COUNT(CODDOCRELE) AS DECIMAL(4,2)) PERCENT_DIVORCIADO ,
CAST(SUM (EST_CIVIL_SOLTERO)/COUNT(CODDOCRELE) AS DECIMAL(4,2)) PERCENT_SOLTERO ,
CAST(SUM (EST_CIVIL_CASADO)/COUNT(CODDOCRELE) AS DECIMAL(4,2)) PERCENT_CASADO,
CAST(SUM (EST_CIVIL_VIUDO)/COUNT(CODDOCRELE) AS DECIMAL(4,2)) PERCENT_VIUDO,
CAST(SUM(EST_CIVIL_FEMENINO)/COUNT(CODDOCRELE) AS DECIMAL(4,2)) PERCENT_FEMENINO,
CAST(SUM(EST_CIVIL_MASCULINO)/COUNT(CODDOCRELE) AS DECIMAL(4,2)) PERCENT_MASCULINO
FROM (.............T1_VPC_SUNAT_RENIEC_HIST) SUNAT
GROUP BY NUMRUC
Revise this Paste