Something along the lines of this...first I'd combine your conference size queries into one view:
-- Or maybe conf_size_counts ??
CREATE VIEW conf_sizes AS
SELECT
c2.id,
sum(if(value<11,1,0)) AS "conf10",
sum(if(value<20 and value>10,1,0)) AS "conf20",
sum(if(value>20,1,0)) AS "conf30"
FROM extension ext, client c1, client c2, extension_prefs exp
WHERE ext.client_id = c1.id
AND exp.param="conf_size"
AND ext.type="conference"
AND c1.parent_client_id = c2.id
AND exp.extension_id = ext.id
GROUP BY c2.id;
Then modify your main query as:
SELECT c.id, c.name, cs.conf10, cs.conf20, cs.conf30
FROM client c LEFT OUTER JOIN conf_sizes cs ON c.id = cs.id
WHERE c.level = 50
AND c.status = 1
The rest of the views and joins I leave for you... |