我想用不同的值
两次选择2列SELECT id FROM ads WHERE onoff='1' AND again='0'
SELECT id FROM ads WHERE onoff='2' AND again='1'
SELECT id FROM ads WHERE onoff='3' AND again='1'
有没有办法在一个sql中完成所有这些?
答案 0 :(得分:6)
SELECT id
FROM ads
WHERE (onoff = '1' AND again = '0')
OR (onoff = '2' AND again = '1')
OR (onoff = '3' AND again = '1')
答案 1 :(得分:1)
比使用OR更好的执行:
SELECT id FROM ads WHERE onoff='1' AND again='0'
UNION ALL
SELECT id FROM ads WHERE onoff='2' AND again='1'
UNION ALL
SELECT id FROM ads WHERE onoff='3' AND again='1'
OR
SELECT ID FROM ADS WHERE onoff='1' AND again='0'
OR (onoff IN( '2','3') AND again = '1')