You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'AND r.rng_id = fstc.rng_id AND fstc.fstc_status = 3 GROUP BY r.rng_id ORDER ...' at line 1