请帮助将这两个陈述混合到一个陈述中:
SELECT * FROM inventory WHERE
{pro_status {1}} {pro_status {1}}
='1' or
loca_city ='2'
='usa'`
我需要声明1的结果来做声明2.
SELECT * FROM inventory WHERE
需要结果:
= 'tw' or loca_city
答案 0 :(得分:3)
您需要将相应的过滤器与AND
结合使用(注意在它们周围加上括号以强制执行所需的优先级):
SELECT *
FROM inventory
WHERE (`pro_status`='1' or `pro_status`='2')
AND (`loca_city` = 'hk' or `loca_city` = 'tw' or loca_city` = 'usa')
使用MySQL IN()
运算符可以简化条件:
SELECT *
FROM inventory
WHERE pro_status IN (1,2)
AND loca_city IN ('hk','tw','usa')
答案 1 :(得分:0)
如果两个查询都在同一个表上且所有条件都是OR
,您可以直接执行:
SELECT
*
FROM inventory
WHERE `pro_status`='1' or `pro_status`='2'
OR `loca_city` = 'hk' or `loca_city` = 'tw' or `loca_city` = '
答案 2 :(得分:0)
SELECT * FROM inventory
WHERE `pro_status`='1'
OR `pro_status`='2'
OR `loca_city` = 'hk'
OR `loca_city` = 'tw'
OR loca_city` = 'usa'