开发者

MYSQL if statement (From mysql newb)

开发者 https://www.devze.com 2022-12-13 20:37 出处:网络
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.

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...
0

精彩评论

暂无评论...
验证码 换一张
取 消