有一张表,里面有字段 
A        B        C  
---------------------
01       42F9A            
0101     E654B    01  
0102     EC7D5    01 
0103     CBC99    02
0104     C5480    01
0105     95EAC    01
02       73718
0201     F626F    01
0202     044FB    02
0203     EAD27    02
(注:0101为01的下级,0201为02的下级)
我想在这张表里统计出A列下的01和02的下级有多少,A列下的01和02下的C列中01有多少,02有多少高手请帮忙看看,我对SQL语句写的比较少,原来都写些简单的

解决方案 »

  1.   

    select count(*) from table where table.A like '01%' or table.A like '02%';select substr(A,0,2),C,count(*) from table where table.A like '01%' or table.A like '02%' group by substr(A,0,2),C;select substr(A,0,2),C,count(*) from table where table.A like '01%' or table.A like '02%' group by substr(A,0,2),C;select C,count(*) from table where table.A like '01%' or table.A like '02%' group by C;
      

  2.   


    --A列下 01  02 多少个
    select count(substring(A,1,2)) -1 from yyq4 group by substring(A,1,2)--以此类推
      

  3.   

    我是要出四列数据,第一列出01和02,第二列出01和02的下级的统计数值,第三列出A列01和02下C列中01的统计数,第四列出A列01和02下C列中02的统计数
    一    二   三    四
    -------------------
    01   5    4    1
    02   3    1    2要出这样的
    再请高手帮忙
      

  4.   

    我是要出四列数据,第一列出01和02,第二列出01和02的下级的统计数值,第三列出A列01和02下C列中01的统计数,第四列出A列01和02下C列中02的统计数
    一 二 三 四
    -------------------
    01 5 4 1
    02 3 1 2要出这样的
    再请高手帮忙
      

  5.   


    select a.id, a.cnt,b.cnt,c.cnt from (select substring(A,1,2) id, count(substring(A,1,2)) -1 cnt
    from tabName group by substring(A,1,2)) a,
    (select C id,count(C) cnt from tabName
    where A like '01%' and C <> '' group by C) b,
    (select C id,count(C) cnt from tabName
    where A like '02%' and C <> '' group by C) c
    where a.A = b.A and a.A = c.A
    -----------------------------------------------
    id   a.cnt b.cnt c.cnt
    '01', 5, 4, 1
    '02', 3, 1, 2