我一直在网上查看SQL IF语句,我似乎无法理解他们。这是我目前拥有的
SELECT * FROM items WHERE location = '$UserHomeTown[0]' OR deliver = '1' OR post = '1'
但如果deliver = 1
我需要选择location1并将其与$UserHomeTown[1]
进行比较,
我试过了
SELECT * FROM items WHERE location = '$UserHomeTown[0]' OR post = '1' OR IF(deliver == '1')THEN location1 = '$UserHomeTown[1]'
但我没有运气。
我需要的是
答案 0 :(得分:0)
您可以在CASE
子句中使用WHERE
-
WHERE
location = '$UserHomeTown[0]' OR
post = '1' OR
CASE
WHEN deliver='1' THEN location1='$UserHomeTown[1]'
ELSE ''
END
答案 1 :(得分:0)
您可以在AND
条款中使用OR
WHERE
交换if或case:
SELECT * FROM items WHERE
location = '$UserHomeTown[0]' OR post = '1' OR
(deliver == '1' and location1 = '$UserHomeTown[1]')