Oracle - return multiple counts as one query

前端 未结 3 1615
旧巷少年郎
旧巷少年郎 2021-02-19 11:50

I have a couple of queries, detailed below. I\'d like to be able to run one SQL query which returns both counts, is this possible?

1.

select nvl(count(ro         


        
3条回答
  •  星月不相逢
    2021-02-19 12:28

    If you need them in a single row:

    SELECT
        COUNT(CASE OPP WHEN 'FOO' THEN 1 END),
        COUNT(CASE OPP WHEN 'BAR' THEN 1 END)
    FROM tablename
    WHERE OPP IN ('FOO', 'BAR') AND date = 'BAZ'
    

    (The GROUP BY approach by Thilo is a better generic solution anyway.)

    Edit: I've removed NVL(). I had forgotten why I never use it.

提交回复
热议问题