如何在MySQL查詢中編寫IF ELSE語句?像這樣:mysql_query("...(irrelevant code).. IF(action==2&&state==0){state=1}");然后在我的數(shù)組中,我應(yīng)該能夠做到這一點(diǎn): $row['state'] //this should equal 1, the query should not change anything in the database, //just the variable for returning the information
3 回答

阿波羅的戰(zhàn)車
TA貢獻(xiàn)1862條經(jīng)驗(yàn) 獲得超6個(gè)贊
您可能要使用CASE表達(dá)式。
他們看起來像這樣:
SELECT col1, col2, (case when (action = 2 and state = 0)
THEN
1
ELSE
0
END)

慕桂英546537
TA貢獻(xiàn)1848條經(jīng)驗(yàn) 獲得超10個(gè)贊
您必須使用SQL而不是C / PHP樣式編寫它
IF( action = 2 AND state = 0, 1, 0 ) AS state
用于查詢
IF ( action = 2 AND state = 0 ) THEN SET state = 1
用于存儲(chǔ)過程或函數(shù)
添加回答
舉報(bào)
0/150
提交
取消