jeudi 20 décembre 2018

How to fix if-statement in where clause mysql

I have a few problems here which make me confused, can you help me?

1064 - 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 'ELSE m.km_oli >= m.warning_update)' at line 6

select `m`.`kode_kendaraan` AS `kode_kendaraan`,`m`.`rotasi_kilometer` AS `rotasik`,`m`.`km_oli` AS `km_oli`,`m`.`warning_kmoli` AS `warning_kmoli`,concat(substr(`m`.`km_oli`,1,2),'','0000') AS `angka_bulat`,concat(substr(`m`.`km_oli`,1,2),'',`m`.`warning_kmoli`) AS `angka_warning`,(concat(substr(`m`.`km_oli`,1,2),'','0000') + `m`.`rotasi_kilometer`) AS `angka_minimal`,`m`.`rotasi_update` AS `rotasi_update`,`m`.`warning_update` AS `warning_update`,`m`.`angkakm_terakhir` AS `angkakm_terakhir`,`m`.`angkawarning_terakhir` AS `angkawarning_terakhir`,`m`.`angkaminimal_terakhir` AS `angkaminimal_terakhir` from `modern`.`mobil` `m` where char_length(`m`.`km_oli`) = 6 and IF(`m`.`rotasi_update` = 0, `m`.`km_oli` >= concat(substr(`m`.`km_oli`,1,2),'',`m`.`warning_kmoli`), ELSE `m`.`km_oli` >= `m`.`warning_update`)

Aucun commentaire:

Enregistrer un commentaire