Oracle统计多个,满足条件的字段的数

Table:ABCTable

a    b     c

1    2     1

2    1     3

3    1     2

统计a=1的有几个,b=1的有几个,c=1的有几个

1. select  count(*)  from ABCTable where a=1;

    select  count(*)  from ABCTable where b=1;

    select  count(*)  from ABCTable where c=1;

2. SELECT  SUM(CASE WHEN a=1 THEN 1 ELSE 0 END) ,

                         SUM(CASE WHEN b=1 THEN 1 ELSE 0 END) ,

                   SUM(CASE WHEN c=1 THEN 1 ELSE 0 END) ,

     FROM  ABCTable t ;  

猜你喜欢

转载自beyondbn.iteye.com/blog/1816836