0

我想加入这两个查询以在一个查询中获得结果。我怎么做?

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
4

3 回答 3

3

为什么需要分开查询?

尝试使用类似的东西

SELECT  Serial_no,
        BOOTH_NO 
FROM    table 
WHERE   BOOTH_NO IN ('1','2')
OR      (BOOTH_NO IN ('3','4') AND [serial_no]%2=0)
于 2013-08-12T06:11:50.870 回答
1

您可以使用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)
于 2013-08-12T06:09:49.010 回答
1
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
于 2013-08-12T06:12:04.613 回答