SELECT COUNT ( `b` . `id` ) AS `bugcount` , `c` . `name` AS `category_name` , `category_id` , `b` . `status` FROM `mantis_bug_table` `b` JOIN `mantis_category_table` `c` ON `b` . `category_id` = `c` . `id` WHERE `b` . `project_id` = ? AND `b` . `id` IN ( SELECT `mantis_bug_table` . `id` FROM `mantis_bug_table` JOIN `mantis_project_table` ON `mantis_project_table` . `id` = `mantis_bug_table` . `project_id` WHERE `mantis_project_table` . `enabled` = ? AND ( `mantis_bug_table` . `project_id` = ? ) ) GROUP BY `c` . `name` , `b` . `category_id` , `b` . `status` ORDER BY `c` . `name` 