我正在使用以下SQL查询
SELECT count(column1) from table1 where CONDITION1
UNION
SELECT count(column1) from table1 where CONDITION2;
当我运行查询时,它会在结果中给出两个数字。但我需要一个数字结果,它将计算上述操作中的记录数。我不知道如何编写该查询。有人能帮助我吗?
答案 0 :(得分:4)
请尝试:
SELECT count(column1) from table1 where CONDITION1 OR CONDITION2
答案 1 :(得分:3)
这取决于您是否打算table1
两次
SELECT
SUM(TheCount)
FROM
(
SELECT count(column1) AS TheCount from table1 where CONDITION1
UNION
SELECT count(column1) from table1 where CONDITION2
) X;
或
SELECT count(column1) AS TheCount
from table1
where (CONDITION1) OR (CONDITION2);