SELECT *
FROM (
SELECT zone_id, GROUP_CONCAT(DISTINCT country_id) AS country_id, GROUP_CONCAT(DISTINCT os_id) AS os_id,
# all geos | all os
' ' AS `1 ALL GEOS | ALL OS`,
IFNULL(GROUP_CONCAT(IF(country_id = 9999 AND os_id = 9999, deal_id, NULL)), 0) AS 1_deal_ids,
COUNT(DISTINCT IF(country_id = 9999 AND os_id = 9999, 1, 0)) AS 1_deals,
SUM(IF(country_id = 9999 AND os_id = 9999, allocation_pct, 0)) AS 1_alloc,
SUM(IF(country_id = 9999 AND os_id = 9999, weight, 0)) AS 1_weight,
# all geos | specific os
' ' AS `2 ALL GEOS | SPECIFIC OS`,
IFNULL(GROUP_CONCAT(IF(country_id = 9999 AND os_id != 9999, deal_id, NULL)), 0) AS 2_deal_ids,
COUNT(DISTINCT IF(country_id = 9999 AND os_id != 9999, 1, 0)) AS 2_deals,
SUM(IF(country_id = 9999 AND os_id != 9999, allocation_pct, 0)) AS 2_alloc,
SUM(IF(country_id = 9999 AND os_id != 9999, weight, 0)) AS 2_weight,
# specific geos | all os
' ' AS `3 SPECIFIC GEOS | ALL OS`,
IFNULL(GROUP_CONCAT(IF(country_id != 9999 AND os_id = 9999, deal_id, NULL)), 0) AS 3_deal_ids,
COUNT(DISTINCT IF(country_id != 9999 AND os_id = 9999, 1, 0)) AS 3_deals,
SUM(IF(country_id != 9999 AND os_id = 9999, allocation_pct, 0)) AS 3_alloc,
SUM(IF(country_id != 9999 AND os_id = 9999, weight, 0)) AS 3_weight,
# specific geos | specific os
' ' AS `4 SPECIFIC GEOS | SPECIFIC OS`,
IFNULL(GROUP_CONCAT(IF(country_id != 9999 AND os_id != 9999, deal_id, NULL)), 0) AS 4_deal_ids,
COUNT(DISTINCT IF(country_id != 9999 AND os_id != 9999, 1, 0)) AS 4_deals,
SUM(IF(country_id != 9999 AND os_id != 9999, allocation_pct, 0)) AS 4_alloc,
SUM(IF(country_id != 9999 AND os_id != 9999, weight, 0)) AS 4_weight
FROM `campaigns_deals_zones`
WHERE `status` = 1 AND zone_id = 39450
AND (country_id = 840 OR country_id = 9999)
AND (os_id = 100 OR os_id = 9999)
GROUP BY zone_id
) AS tbl