2014-02-24 55 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