SELECT ia.`inquiryanswer_id`, ia.`description`, count(ir.`inquiryresponse_id`) / (SELECT IF(COUNT(ir2.`inquiryresponse_id`) = 0, 1, COUNT(ir2.`inquiryresponse_id`)) FROM `inquiryresponse` ir2 INNER JOIN `inquiryanswer` ia2 ON ir2.`inquiryanswer_id` = ia2.`inquiryanswer_id` WHERE ia2.`inquiry_id` = ) * 100 AS `percent` FROM `inquiryanswer` ia LEFT OUTER JOIN `inquiryresponse` ir ON ia.`inquiryanswer_id` = ir.`inquiryanswer_id` WHERE ia.`inquiry_id` = GROUP BY ia.`description` ORDER BY ia.`sortorder`
MySQL error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') * 100 AS `percent` FROM `inquiryanswer` ia LEFT OUTER JOIN `inquiryresponse`' at line 1