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 ') nj2, (select count(*) from t_leg_cargo lc WHERE lc.id_partido = -1 AND lc.id_' at line 3SELECT (select sum(if(v.id_voto<>4,1,0)) FROM t_leg_cargo lc INNER JOIN t_votacion v ON lc.id_leg_cargo = v.id_leg_cargo WHERE 1 AND lc.fecha_inicio >= '2012-09-01' AND lc.fecha_fin <= '2015-08-31' AND v.id_leg = -1) j1, (select sum(if(v.id_voto<>4,1,0)) j2 FROM t_votacion v INNER JOIN t_legislador l ON v.id_leg = l.id_leg INNER JOIN t_leg_cargo lc ON l.id_leg = lc.id_leg INNER JOIN t_dictamen d on v.id_dictamen = d.id_dictamen WHERE 1 AND lc.fecha_inicio >= '2012-09-01' AND lc.fecha_fin <= '2015-08-31' AND v.id_partido = -1 AND d.fecha >= '2012-09-01' AND d.fecha <= '2015-08-31' AND lc.id_cargo = ) nj2, (select count(*) from t_leg_cargo lc WHERE lc.id_partido = -1 AND lc.id_cargo = AND lc.fecha_inicio >= '2012-09-01' AND lc.fecha_fin <= '2015-08-31' AND lc.id_leg_suplente<>0) dj2, (select sum(if(v.id_voto<>4,1,0)) j2 FROM t_votacion v INNER JOIN t_legislador l ON v.id_leg = l.id_leg INNER JOIN t_leg_cargo lc ON l.id_leg = lc.id_leg INNER JOIN t_dictamen d on v.id_dictamen = d.id_dictamen WHERE 1 AND lc.fecha_inicio >= '2012-09-01' AND lc.fecha_fin <= '2015-08-31' AND d.fecha >= '2012-09-01' AND d.fecha <= '2015-08-31' AND lc.id_cargo = ) nj3, (select count(*) from t_leg_cargo lc WHERE 1 AND lc.id_cargo = AND lc.fecha_inicio >= '2012-09-01' AND lc.fecha_fin <= '2015-08-31' AND lc.id_leg_suplente<>0) dj3, (select nj2/dj2) j2, (select (nj3/dj3))j3, (select count(v.id_voto) FROM t_votacion v LEFT JOIN t_legislador l ON v.id_leg = l.id_leg LEFT JOIN t_leg_cargo lc ON l.id_leg = lc.id_leg INNER JOIN t_dictamen d ON v.id_dictamen = d.id_dictamen WHERE 1 AND d.fecha >= '2012-09-01' AND d.fecha <= '2015-08-31' AND lc.fecha_inicio >= '2012-09-01' AND lc.fecha_fin <= '2015-08-31' AND l.id_leg = -1) dk1, (select count(v.id_voto) FROM t_votacion v INNER JOIN t_leg_cargo lc ON v.id_leg = lc.id_leg INNER JOIN t_dictamen d ON v.id_dictamen = d.id_dictamen WHERE 1 AND d.fecha >= '2012-09-01' AND d.fecha <= '2015-08-31' AND lc.fecha_inicio >= '2012-09-01' AND lc.fecha_fin <= '2015-08-31' AND v.id_partido = -1 and lc.id_cargo = ) dk2, (select count(v.id_voto) FROM t_votacion v INNER JOIN t_leg_cargo lc ON v.id_leg = lc.id_leg INNER JOIN t_dictamen d ON v.id_dictamen = d.id_dictamen WHERE 1 AND d.fecha >= '2012-09-01' AND d.fecha <= '2015-08-31' AND lc.fecha_inicio >= '2012-09-01' AND lc.fecha_fin <= '2015-08-31' AND lc.id_cargo = ) dk3, (select (100*j1/dk1)) k1, (select (100*nj2/dk2)) k2, (select (100*nj3/dk3)) k3