Trying to get this query to work. I’m having issues with brackets I think.
SELECT (fielda - fieldb - (
IF ((cola <= 5),
1,
IF ((cola >= 6 AND cola <= 12),
2,
IF ((cola >= 13 AND cola <= 20),
3,
IF ((cola >= 21 AND cola <= 28), 4)
)
)
) ))
AS result FROM the table r WHERE r.fieldx = 3148 AND cola <= 18 ORDER BY result LIMIT 1
Mysql returns:
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 ‘)))) ) AS result FROM
The last
IFdoes not have an else argument. While one might expect MySQL to understand this anyhow, it doesn’t appear to be valid syntax according to http://dev.mysql.com/doc/refman/5.0/en/control-flow-functions.html#function_if