2014-02-24 53 views
0

添加第二個計數專欄中,我有一個查詢,如下所示的正常工作:SELECT INTO查詢使用不同條款

select id_matched 
    , count(*) s_count 
    into STEVEN_1c 
    from batch 
where match = 200 
group by 
     id_matched 

現在,我想在此查詢其稍微更具體的查詢添加第二個計列其中還檢查另一列即添加一列名爲「count_unique」,其中列「獨一無二」 = 1

因此,像

select id_matched 
    , count(*) s_count 
    , count(* + and unique=1) count_unique 
    into STEVEN_1c 
    from batch 
where match = 200 
group by 
     id_matched 

只是不知道什麼語法應該增加一個比第一個更具體的第二個數列嗎?

回答

0

試試這個:

select id_matched 
    , count(*) s_count 
    , sum(case when unique = 1 then 1 else 0 end) count_unique 
    into STEVEN_1c 
    from batch 
where match = 200 
group by 
     id_matched 
0

你可以寫在下面計數功能的情形條件:

select id_matched 
, count(*) s_count 
, count(case [unique] when 1 then 1 else null end) as count_unique 
into STEVEN_1c 
from batch 
where match = 200 
group by 
id_matched