0

我正在使用以下 SQL 查询

SELECT count(column1) from table1 where CONDITION1
UNION
SELECT count(column1) from table1 where CONDITION2;

当我运行查询时,它会给出两个结果。但我需要一个数字结果,它将计算上述操作的记录数。我不知道如何编写该查询。有谁能够帮我?

4

2 回答 2

4

请试试:

SELECT count(column1) from table1 where CONDITION1 OR CONDITION2
于 2013-05-15T10:54:25.083 回答
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);
于 2013-05-15T10:53:47.403 回答