A   B
---------
A    Y
A    N
A    Y
B    Y
B    Y
A    N
怎么用一个查询语句分别统计两列中的数量呢。。

解决方案 »

  1.   

    select count(distinct A) from tablename
    union all
    select count(distinct B) from tablename
    --例如
    SQL> select count(distinct empno) from emp
      2  union all
      3  select count(distinct deptno) from emp;COUNT(DISTINCTEMPNO)
    --------------------
                      14
                       3
      

  2.   

    --难道是这样?
    select count(*) from table group by A,B
      

  3.   

    select count(*) from table where A='A'select count(*) from table where B='Y'这两个数据集查着是分开的,用一条语句得到这两条语句的结果,输出结果示例
    countA countB
    -------------
      4      4   
      

  4.   

    select a, count(a)
    from table_ab group by a
    union
    select b, count(b)
    from table_ab group by b;不過a和b字段類型應該要一樣才行
      

  5.   

     select sum(decode(b,'y',1,0)),sum(decode(A,'a',1,0)) from tb
      

  6.   

    select m.*, n.* from
    (select count(*) from table where A='A') m,
    (select count(*) from table where B='Y')
      

  7.   


    select SUM(decode(A,'A',1,0)) countA ,SUM(decode(B,'Y',1,0))countB
    from table ;
      

  8.   

    select 
      sum(case when A='A' then 1 else 0 end) ,
      sum(case when B='Y' then 1 else 0 end)
    from tb
      

  9.   

    select SUM(decode(A,'A',1,0)) countA ,SUM(decode(B,'Y',1,0))countB
    from table ;
      

  10.   

    select 
      count(case when A='A' then 1 else null end) ,
      count(case when B='Y' then 1 else null end)
    from tb
    select (select count(*) from tb where A='A'),
           (select count(*) from tb where B='Y')
    from dual
      

  11.   


    select (select count(*) from tb where A='A'),
           (select count(*) from tb where B='Y')
    from dual
    这个也
      

  12.   

    create table aa(a varchar2(4),b varchar2(4));
     
    select * from (
    select count(*),a from aa group by a
     union 
    select count(*),b from aa group by b);
      

  13.   

    结果是:
    COUNT(*)   A
    ---------- ----
             2 B
             3 N
             4 Y
             5 A
      

  14.   

    全是SQL啊。哈哈。都是高手。
      

  15.   

    可以参考select count(decode(a,'A','A')),count(decode(B,'B','B'))  from test_AB
      

  16.   

    SELECT count(A),count(b) FROM TABLE_NAME
      

  17.   

    select m.*, n.* from
    (select count(*) from table where A='A') m,
    (select count(*) from table where B='Y')