如何在MySQL查询中编写IF ELSE语句?

像这样:

mysql_query("...(irrelevant code).. IF(action==2&&state==0){state=1}");

然后在我的数组中,我应该能够做到这一点:
 $row['state']
//this should equal 1, the query should not change anything in the database,
//just the variable for returning the information

最佳答案

您可能要使用 CASE expression

他们看起来像这样:

SELECT col1, col2, (case when (action = 2 and state = 0)
 THEN
      1
 ELSE
      0
 END)
 as state from tbl1;

关于mysql - 如何在MySQL查询中编写IF ELSE语句,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8763310/

10-09 22:56
查看更多