Search code examples
sqloracle11g

how to count two different values from same column in oracle


I have a table connection_master in that table column name status_conn have 1 value for ON conn. and 2 for OFF conn. now I want to get only counts of ON and OFF connections in one query

I want output like this

on_counts   off_counts
110         55

Solution

  • Use conditional aggregation:

    SELECT
        COUNT(CASE WHEN status_conn = 1 THEN 1 END) AS on_counts,
        COUNT(CASE WHEN status_conn = 2 THEN 1 END) AS off_counts
    FROM connection_master;