optimizing mysql if - else depend on my case
in my case, I want to make branching in mysql like this :
- if office_id is not null then is_invited = 1
- else if office_id = '0000' then is_invited = 1
- else is_invited = 0
after I saw @thomasrutter answer here " if else query in mysql "..
I made query like this on mysql :select IF(y.office_id IS NOT NULL, 1, IF(y.office_id = '0000', 1, IF(y.office_id IS NULL, 0, 1))) as is_invited
my question is,, can I make the query to be more optimize (with respect 开发者_运维知识库to performance)
many thanks :)
Your logic doesn't make sense here.
Case 2 is always satisfied/never reached. If office_id is not null, then you already assign is_invited = 1. So office_id = '0000' will never be tested, since it's always not null. Really, your logic should simply be IF(y.office_id IS NOT NULL, 1, 0) as is_invited
精彩评论