I want to write something like
if(?) x elseif(?) y else z
and also I want to use CASE WHEN FOR THIS.
MySql has IF(cond, true, false)
. You can nest them.
So you can do IF(a, x, IF(b, y, z))
for if(a) x elseif(b) y else z
You can also write
CASE WHEN a THEN x
WHEN b THEN y
ELSE z END
to do the same thing. Pretty straightforward. Some other makes of DBMS server use IIF()
instead of IF()
.