CREATE MULTISET TABLE ..........................................HM_CIMA_RCC_CLASS_PREVIA AS (
    SELECT PERIODO, RUC,
	COUNT(CASE WHEN DIF=2 OR DIF IS NULL THEN CTDENTIDADREPORTANTE ELSE 0 END) AS CTDENTDEUDORAS,
	MAX(CASE WHEN DIF=2 OR DIF IS NULL THEN PCTNORMAL ELSE 0 END) AS PCTNORMAL,
	MAX(CASE WHEN DIF=2 OR DIF IS NULL THEN PCTCPP ELSE 0 END) AS PCTCPP,
	MAX(CASE WHEN DIF=2 OR DIF IS NULL THEN PCTDEFICIENTE ELSE 0 END) AS PCTDEFICIENTE,
	MAX(CASE WHEN DIF=2 OR DIF IS NULL THEN PCTDUDOSO ELSE 0 END) AS PCTDUDOSO,
	MAX(CASE WHEN DIF=2 OR DIF IS NULL THEN PCTPERDIDA ELSE 0 END) AS PCTPERDIDA,

	MAX(CASE WHEN DIF<=4 OR DIF IS NULL THEN PCTNORMAL ELSE 0 END) AS PCTNORMAL_3M,
	MAX(CASE WHEN DIF<=4 OR DIF IS NULL THEN PCTCPP ELSE 0 END) AS PCTCPP_3M,
	MAX(CASE WHEN DIF<=4 OR DIF IS NULL THEN PCTDEFICIENTE ELSE 0 END) AS PCTDEFICIENTE_3M,
	MAX(CASE WHEN DIF<=4 OR DIF IS NULL THEN PCTDUDOSO ELSE 0 END) AS PCTDUDOSO_3M,
	MAX(CASE WHEN DIF<=4 OR DIF IS NULL THEN PCTPERDIDA ELSE 0 END) AS PCTPERDIDA_3M,

	MAX(CASE WHEN DIF<=7 OR DIF IS NULL THEN PCTNORMAL ELSE 0 END) AS PCTNORMAL_6M,
	MAX(CASE WHEN DIF<=7 OR DIF IS NULL THEN PCTCPP ELSE 0 END) AS PCTCPP_6M,
	MAX(CASE WHEN DIF<=7 OR DIF IS NULL THEN PCTDEFICIENTE ELSE 0 END) AS PCTDEFICIENTE_6M,
	MAX(CASE WHEN DIF<=7 OR DIF IS NULL THEN PCTDUDOSO ELSE 0 END) AS PCTDUDOSO_6M,
	MAX(CASE WHEN DIF<=7 OR DIF IS NULL THEN PCTPERDIDA ELSE 0 END) AS PCTPERDIDA_6M,

	MAX(PCTNORMAL) AS PCTNORMAL_12M,
	MAX(PCTCPP) AS PCTCPP_12M,
	MAX(PCTDEFICIENTE) AS PCTDEFICIENTE_12M,
	MAX(PCTDUDOSO) AS PCTDUDOSO_12M,
	MAX(PCTPERDIDA) AS PCTPERDIDA_12M
	
	FROM .................................................HM_CIMA_RCC_CLASS
	GROUP BY PERIODO, RUC
)
WITH DATA PRIMARY INDEX (PERIODO, RUC);

Add a code snippet to your website: www.paste.org