SELECT A.AttributeID, ElementID, 0 ArrayIndex, ValidFor, 
	CASE A.AttributeID
		WHEN 1886850 THEN ROUND(((A_123251)/(A_123329)) * 100, 2)
		WHEN 1886849 THEN ROUND(((A_123232)/(A_123329)) * 100, 2)
		WHEN 1886851 THEN ROUND(((A_123263)/(A_123329)) * 100, 2)
		WHEN 1886853 THEN ROUND(((A_123285)/(A_123329)) * 100, 2)
		WHEN 1886859 THEN ROUND(((A_123307)/(A_123329)) * 100, 2)
		WHEN 1886854 THEN ROUND(((A_123296)/(A_123329)) * 100, 2)
		WHEN 1886856 THEN ROUND(((A_123303)/(A_123329)) * 100, 2)
		WHEN 1886852 THEN ROUND(((A_123274)/(A_123329)) * 100, 2)
		WHEN 1886857 THEN ROUND(((A_123305)/(A_123329)) * 100, 2)
		WHEN 1886855 THEN ROUND(((A_123301)/(A_123329)) * 100, 2)
	END DoubleValue, NULL StringValue, FALSE IsDefault
FROM
(
	SELECT ElementID, ValidFor, 0 K,
		NVL(MAX(CASE WHEN AttributeID = 123296 THEN Value END), 0) A_123296, IFNULL(MIN(CASE WHEN AttributeID = 123296 THEN 0 END), -1) D_123296,
		NVL(MAX(CASE WHEN AttributeID = 123303 THEN Value END), 0) A_123303, IFNULL(MIN(CASE WHEN AttributeID = 123303 THEN 0 END), -1) D_123303,
		NVL(MAX(CASE WHEN AttributeID = 123274 THEN Value END), 0) A_123274, IFNULL(MIN(CASE WHEN AttributeID = 123274 THEN 0 END), -1) D_123274,
		NVL(MAX(CASE WHEN AttributeID = 123329 THEN Value END), 0) A_123329, IFNULL(MIN(CASE WHEN AttributeID = 123329 THEN 0 END), -1) D_123329,
		NVL(MAX(CASE WHEN AttributeID = 123285 THEN Value END), 0) A_123285, IFNULL(MIN(CASE WHEN AttributeID = 123285 THEN 0 END), -1) D_123285,
		NVL(MAX(CASE WHEN AttributeID = 123301 THEN Value END), 0) A_123301, IFNULL(MIN(CASE WHEN AttributeID = 123301 THEN 0 END), -1) D_123301,
		NVL(MAX(CASE WHEN AttributeID = 123232 THEN Value END), 0) A_123232, IFNULL(MIN(CASE WHEN AttributeID = 123232 THEN 0 END), -1) D_123232,
		NVL(MAX(CASE WHEN AttributeID = 123307 THEN Value END), 0) A_123307, IFNULL(MIN(CASE WHEN AttributeID = 123307 THEN 0 END), -1) D_123307,
		NVL(MAX(CASE WHEN AttributeID = 123251 THEN Value END), 0) A_123251, IFNULL(MIN(CASE WHEN AttributeID = 123251 THEN 0 END), -1) D_123251,
		NVL(MAX(CASE WHEN AttributeID = 123305 THEN Value END), 0) A_123305, IFNULL(MIN(CASE WHEN AttributeID = 123305 THEN 0 END), -1) D_123305,
		NVL(MAX(CASE WHEN AttributeID = 123263 THEN Value END), 0) A_123263, IFNULL(MIN(CASE WHEN AttributeID = 123263 THEN 0 END), -1) D_123263
	FROM
	(
SELECT AttributeID, ElementID, ValidFor, SUM(CASE WHEN (AttributeID,HistType,DimValue) = (123232,'CT_PropDelay',0) OR (AttributeID,HistType,DimValue) = (123251,'CT_PropDelay',1) OR (AttributeID,HistType,DimValue) = (123263,'CT_PropDelay',2) OR (AttributeID,HistType,DimValue) = (123274,'CT_PropDelay',3) OR (AttributeID,HistType,DimValue) = (123285,'CT_PropDelay',4) OR (AttributeID,HistType,DimValue) = (123296,'CT_PropDelay',5) OR (AttributeID,HistType,DimValue) = (123301,'CT_PropDelay',6) OR (AttributeID,HistType,DimValue) = (123303,'CT_PropDelay',7) OR (AttributeID,HistType,DimValue) = (123305,'CT_PropDelay',8) OR (AttributeID,HistType,DimValue) = (123307,'CT_PropDelay',9) OR (AttributeID = 123329 AND HistType = 'CT_PropDelay' AND DimValue BETWEEN 0 AND 203) THEN DimCount END) Value
FROM
(
SELECT ElementID, TIMESTAMP(Date) ValidFor, HistType,DimValue, SUM(DimCount) DimCount, 0 K
FROM UMTS_HIST_SECTOR_DAILY
WHERE ElementID IN (23277)
	AND Date = DATE('2018-06-29')
	AND (HistType IN ('CT_PropDelay')) AND (DimValue IN (0,1,2,3,4,5,6,7,8,9) OR DimValue BETWEEN 0 AND 203)
GROUP BY ElementID, ValidFor, HistType,DimValue
) V
	JOIN (SELECT 123232 AttributeID, 0 K UNION ALL SELECT 123251,0 UNION ALL SELECT 123263,0 UNION ALL SELECT 123274,0 UNION ALL SELECT 123285,0 UNION ALL SELECT 123296,0 UNION ALL SELECT 123301,0 UNION ALL SELECT 123303,0 UNION ALL SELECT 123305,0 UNION ALL SELECT 123307,0 UNION ALL SELECT 123329,0) A
		ON V.K = A.K
GROUP BY AttributeID, ElementID, ValidFor
HAVING Value IS NOT NULL
	) V
	GROUP BY ElementID, ValidFor
) P
	JOIN (SELECT 1886850 AttributeID, 0 K UNION ALL SELECT 1886849, 0 UNION ALL SELECT 1886851, 0 UNION ALL SELECT 1886853, 0 UNION ALL SELECT 1886859, 0 UNION ALL SELECT 1886854, 0 UNION ALL SELECT 1886856, 0 UNION ALL SELECT 1886852, 0 UNION ALL SELECT 1886857, 0 UNION ALL SELECT 1886855, 0) A
		ON P.K = A.K
WHERE 
	CASE A.AttributeID
		WHEN 1886849 THEN D_123232
		WHEN 1886850 THEN D_123251
		WHEN 1886851 THEN D_123263
		WHEN 1886852 THEN D_123274
		WHEN 1886853 THEN D_123285
		WHEN 1886854 THEN D_123296
		WHEN 1886855 THEN D_123301
		WHEN 1886856 THEN D_123303
		WHEN 1886857 THEN D_123305
		WHEN 1886859 THEN D_123307
	END > -1
HAVING DoubleValue IS NOT NULL
UNION ALL
SELECT AttributeID, ElementID, 0 ArrayIndex, ValidFor, DimCount DoubleValue, NULL StringValue, FALSE IsDefault
FROM
(
SELECT ElementID, TIMESTAMP(Date) ValidFor, HistType,DimValue, SUM(DimCount) DimCount
FROM UMTS_HIST_SECTOR_DAILY
WHERE ElementID IN (23277)
	AND Date = DATE('2018-06-29')
	AND (HistType IN ('CT_PropDelay')) AND (DimValue IN (0,1,2,3,4,5,6,7,8,9))
GROUP BY ElementID, ValidFor, HistType,DimValue
) V
	JOIN (SELECT 123232 AttributeID, 'CT_PropDelay' HistType,0 DimValue UNION ALL SELECT 123251,'CT_PropDelay',1 UNION ALL SELECT 123263,'CT_PropDelay',2 UNION ALL SELECT 123274,'CT_PropDelay',3 UNION ALL SELECT 123285,'CT_PropDelay',4 UNION ALL SELECT 123296,'CT_PropDelay',5 UNION ALL SELECT 123301,'CT_PropDelay',6 UNION ALL SELECT 123303,'CT_PropDelay',7 UNION ALL SELECT 123305,'CT_PropDelay',8 UNION ALL SELECT 123307,'CT_PropDelay',9) A
		ON (V.HistType,V.DimValue) = (A.HistType,A.DimValue)
HAVING DoubleValue IS NOT NULL