CREATE MULTISET TABLE ........................................T3_VPC_DETALLE_VARIACION_SUNAT_RENIEC_HIST AS
(
SELECT AA.PERIODO PERIODO,
AA.NUMRUC NUMRUC,
BB.PERIODO PERIODO_COMPRA_ANTERIOR,
CASE WHEN BB.MAX_NUMTRABAJADORES = 0 THEN 0 ELSE AA.MAX_NUMTRABAJADORES / BB.MAX_NUMTRABAJADORES END VARIACION_PORCENTUAL_NUMTRABAJADORES,
CASE WHEN BB.MAX_MONTODEUDATRIBUTO = 0 THEN 0 ELSE AA.MAX_MONTODEUDATRIBUTO / BB.MAX_MONTODEUDATRIBUTO END VARIACION_PORCENTUAL_MONTODEUDATRIBUTO,
CASE WHEN BB.PROMEDIO_EDAD_RRLL = 0 THEN 0 ELSE AA.PROMEDIO_EDAD_RRLL / BB.PROMEDIO_EDAD_RRLL END VARIACION_PORCENTUAL_EDAD_RRLL,
CASE WHEN BB.RANGOVENTAS = 0 THEN 0 ELSE AA.RANGOVENTAS / BB.RANGOVENTAS END VARIACION_PORCENTUAL_RANGOVENTAS,
CASE WHEN BB.CNT_GEN_F = 0 THEN 0 ELSE AA.CNT_GEN_F / BB.CNT_GEN_F END VARIACION_PORCENTUAL_FEMENINO,
CASE WHEN BB.CNT_RESIDENCIA_EXTRANJERA = 0 THEN 0 ELSE AA.CNT_RESIDENCIA_EXTRANJERA / BB.CNT_RESIDENCIA_EXTRANJERA END VARIACION_PORCENTUAL_RESIDENCIA_EXTRANJERA,
CASE WHEN BB.CNT_RRLL = 0 THEN 0 ELSE AA.CNT_RRLL / BB.CNT_RRLL END VARIACION_PORCENTUAL_CNT_RRLL
FROM ........................T2_VPC_DETALLE_SUNAT_RENIEC_HIST AA
LEFT JOIN ...........................T2_VPC_DETALLE_SUNAT_RENIEC_HIST BB
ON = AA.NUMRUC = BB.NUMRUC AND CAST( AA..PERIODO AS DATE FORMAT 'YYYYMM') = ADD_MONTHS (CAST( BB.PERIODO AS DATE FORMAT 'YYYYMM'), -7)
) WITH DATA AND STATS;
Add a code snippet to your website: www.paste.org