我正在使用以下 SQL 查询
SELECT count(column1) from table1 where CONDITION1
UNION
SELECT count(column1) from table1 where CONDITION2;
当我运行查询时,它会给出两个结果。但我需要一个数字结果,它将计算上述操作的记录数。我不知道如何编写该查询。有谁能够帮我?
请试试:
SELECT count(column1) from table1 where CONDITION1 OR CONDITION2
这取决于你是否打算有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);