我想有這樣的事情:Mysql如何在IF中使用IN in where子句?
SELECT
p.name_en AS 'province_$lang',
p.province_code AS 'province_code_$lang',
COUNT(u.id) AS 'total_$lang',
COUNT(u.id) AS total
FROM applications AS a
LEFT JOIN users AS u on u.id = a.user_id
LEFT JOIN provinces AS p on p.province_code = u.province_code
WHERE a.progress_status IN (0,1,2,3) AND IF(a.progress_status = 2,a.denial_type ,1) IN IF(a.`progress_status` = 2,(1,2,3),1)
GROUP BY u.province_code
假設我有在表中的兩個字段其中之一是progress_status
能有這些0,1,2, or 3
價值之一,而另一場denial_type
,可以採取1,2, or 3
,但只有denial_type
可以把這些值之一,當progress_status
爲2 所以我要檢查,如果progress_status
是IN
0,1,2,3和這些記錄其progress_status
爲2,則其denial_type
應該IN
1,2,3
它是一個'選擇query'。你也可以顯示你的整個查詢? –
@MilanGupta我有更新我的問題。 – jones