SELECT ACTION , `date_range` , COUNT ( * ) AS `range_count` FROM ( SELECT ACTION , CASE WHEN `date_modified` BETWEEN ? AND ? THEN ? WHEN `date_modified` BETWEEN ? AND ? THEN ? WHEN `date_modified` BETWEEN ? AND ? THEN ? WHEN `date_modified` BETWEEN ? AND ? THEN ? WHEN `date_modified` BETWEEN ? AND ? THEN ? WHEN `date_modified` BETWEEN ? AND ? THEN ? WHEN `date_modified` BETWEEN ? AND ? THEN ? WHEN `date_modified` BETWEEN ? AND ? THEN ? WHEN `date_modified` BETWEEN ? AND ? THEN ? ELSE - ? END AS `date_range` FROM ( SELECT CASE WHEN `h` . `type` = ? THEN ? WHEN `h` . `type` = ? AND `h` . `old_value` >= ? AND `h` . `new_value` < ? THEN ? WHEN `h` . `type` = ? AND `h` . `old_value` < ? AND `h` . `new_value` >= ? THEN ? ELSE ? END AS ACTION , `date_modified` FROM `mantis_bug_history_table` `h` JOIN `mantis_bug_table` `b` ON `b` . `id` = `h` . `bug_id` WHERE `h` . `date_modified` > ? AND ( `h` . `type` = ? OR `h` . `type` = ? AND `h` . `field_name` = ? ) AND `project_id` IN (...) 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 ( 