-- 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;