我想加入这两个查询以在一个查询中获得结果。我怎么做?
SELECT Serial_no,BOOTH_NO FROM table WHERE BOOTH_NO IN ('1','2');
SELECT serial_no,BOOTH_NO FROM table WHERE BOOTH_NO IN ('3','4') AND [serial_no]%2=0
为什么需要分开查询?
尝试使用类似的东西
SELECT Serial_no,
BOOTH_NO
FROM table
WHERE BOOTH_NO IN ('1','2')
OR (BOOTH_NO IN ('3','4') AND [serial_no]%2=0)
您可以使用UNION
关键字。
(SELECT Serial_no,BOOTH_NO FROM table WHERE BOOTH_NO IN ('1','2'))
UNION
(SELECT serial_no,BOOTH_NO FROM table WHERE BOOTH_NO IN ('3','4') AND [serial_no]%2=0)
select
t.serial_no, t.booth_no
from table as t
where
t.booth_no in ('1','2') or
t.booth_no in ('3','4') and t.[serial_no] % 2 = 0