从同一列中选择不同的变量

Selecting from Same Column into different variables

 Values                 Id's
    
    1                   120
    1                   120
    0                   120
    0                   120
    0                   120
    Not applicable      120
    Not applicable      120
    Empty               120

我想 select 使用单个 select 语句将值 1 计数到不同变量中,并将值 0 计数到不同变量中。可能吗?

可能吗?当然,这是一种选择。第 1 - 10 行中的示例数据;您可能使用的查询从第 11 行开始。

SQL> with test (value, id) as
  2    (select 'n/a'  , 120 from dual union all
  3     select 'n/a'  , 120 from dual union all
  4     select 'empty', 120 from dual union all
  5     select '1'    , 120 from dual union all
  6     select '1'    , 120 from dual union all
  7     select '0'    , 120 from dual union all
  8     select '0'    , 120 from dual union all
  9     select '0'    , 120 from dual
 10    )
 11  select sum(case when value = '1' then 1 else 0 end) cnt_1,
 12         sum(case when value = '0' then 1 else 0 end) cnt_0
 13  from test;

     CNT_1      CNT_0
---------- ----------
         2          3

SQL>