请告诉我一种优化以下查询的方法 请帮助我用aggrgate函数优化联合查询,结果应该是相同的列名
(SELECT `raw_id`, `enodeb`, hour( DATE_SUB(`interval`, INTERVAL 15 MINUTE) ) AS intervaltime,`id_sector`,`metric`, Sum(`interval_count`) as metric_value, `cuase_code`,`qci`, N.network_name as network_name FROM raw_metrics left join networks N on N.network_id = raw_metrics.network_id WHERE 1 AND DATE(DATE_SUB(`interval`, INTERVAL 15 MINUTE)) = "2015-03-12" and `metric` in(SELECT `measurement_name` FROM `c_xml_measurements` left join counter_types CT ON CT.counter_id = c_xml_measurements.counter_type WHERE CT.status = 1 and CT.counter_id in (1,2)) GROUP BY intervaltime, `id_sector`, metric)
UNION ALL
(SELECT `raw_id`, `enodeb`, hour( DATE_SUB(`interval`, INTERVAL 15 MINUTE) ) AS intervaltime,`id_sector`,`metric`, AVG(`metric_value`) as metric_value, `cuase_code`,`qci`, N.network_name as network_name FROM raw_metrics left join networks N on N.network_id = raw_metrics.network_id WHERE 1 AND DATE(DATE_SUB(`interval`, INTERVAL 15 MINUTE)) = "2015-03-12" and `metric` in(SELECT `measurement_name` FROM `c_xml_measurements` left join counter_types CT ON CT.counter_id = c_xml_measurements.counter_type WHERE ((CT.status = 1 and CT.counter_id not in (1,2)) OR (CT.status = 0 and CT.counter_id in (1,2))) and (aggregator= 'AVG' OR aggregator= '') ) GROUP BY intervaltime, `id_sector`, metric)
UNION ALL
(SELECT `raw_id`, `enodeb`, hour( DATE_SUB(`interval`, INTERVAL 15 MINUTE) ) AS intervaltime,`id_sector`,`metric`, MAX(`metric_value`) as metric_value, `cuase_code`,`qci`, N.network_name as network_name FROM raw_metrics left join networks N on N.network_id = raw_metrics.network_id WHERE 1 AND DATE(DATE_SUB(`interval`, INTERVAL 15 MINUTE)) = "2015-03-12" and `metric` in(SELECT `measurement_name` FROM `c_xml_measurements` left join counter_types CT ON CT.counter_id = c_xml_measurements.counter_type WHERE ((CT.status = 1 and CT.counter_id not in (1,2)) OR (CT.status = 0 and CT.counter_id in (1,2))) and (aggregator= 'MAX') ) GROUP BY intervaltime, `id_sector`, metric)
UNION ALL
(SELECT `raw_id`, `enodeb`, hour( DATE_SUB(`interval`, INTERVAL 15 MINUTE) ) AS intervaltime,`id_sector`,`metric`, MIN(`metric_value`) as metric_value, `cuase_code`,`qci`, N.network_name as network_name FROM raw_metrics left join networks N on N.network_id = raw_metrics.network_id WHERE 1 AND DATE(DATE_SUB(`interval`, INTERVAL 15 MINUTE)) = "2015-03-12" and `metric` in(SELECT `measurement_name` FROM `c_xml_measurements` left join counter_types CT ON CT.counter_id = c_xml_measurements.counter_type WHERE ((CT.status = 1 and CT.counter_id not in (1,2)) OR (CT.status = 0 and CT.counter_id in (1,2))) and (aggregator= 'MIN') ) GROUP BY intervaltime, `id_sector`, metric) ORDER BY raw_id DESC