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 'AND s.crimeyearid=169 GROUP BY s.crimeid, ct.title, l.location ORDER BY ct.' at line 12

SELECT s.crimeid, ct.title AS crimetype, l.location ,SUM(CASE WHEN s.crimetypeid=1 THEN 1 ELSE 0 END) AS asb_total ,SUM(CASE WHEN s.crimetypeid=2 THEN 1 ELSE 0 END) AS bur_total ,SUM(CASE s.crimetypeid WHEN 3 THEN 1 WHEN 8 THEN 1 WHEN 9 THEN 1 WHEN 10 THEN 1 WHEN 11 THEN 1 WHEN 12 THEN 1 ELSE 0 END) AS other_total ,SUM(CASE WHEN s.crimetypeid=4 THEN 1 ELSE 0 END) AS rob_total ,SUM(CASE WHEN s.crimetypeid=5 THEN 1 ELSE 0 END) AS veh_total ,SUM(CASE WHEN s.crimetypeid=6 THEN 1 ELSE 0 END) AS vio_total ,SUM(CASE WHEN s.crimetypeid>0 THEN 1 ELSE 0 END) AS all_total FROM crime_s s INNER JOIN location l ON (l.locationid = s.locationid) INNER JOIN crimetype ct ON (ct.typeid = s.crimetypeid) WHERE l.locationid = AND s.crimeyearid=169 GROUP BY s.crimeid, ct.title, l.location ORDER BY ct.title