MYSQL if statement (From mysql newb)
Is it possible to get this if statement to NOT print a column if EQ_Type!='ENGINE'? T开发者_如何学运维he empty column on my out put is bothering me.
select if(EQUIPMENT.EQ_Type='ENGINE',ENGINE.Capacity,'') as Capacity, ....
Thanks for your help.
No, you can't selectively include a column on a row by row basis.
No - you will have to either have a column for all rows, or omit the comun altogether. You can control exactly what is displayed by using CASE
, which is basically the same as you have done using IF
(maybe a tad more self-explanatory):
select case when equipment.eq_type = 'ENGINE' then
engine.capacity
else
'put something you want here'
end as capacity
from...
精彩评论