(1)select 'a',count(fn) where fn='a' union .....

解决方案 »

  1.   

    sql server:
    1、
    select fn,count(*) as ccc from t1 group bu fn
    2、
    select 'a' as a,sum(case when fn='a' then 1 else 0 end) as ac 
    'b' as b,sum(case when fn='b' then 1 else 0 end) as bc,
    'c' as c,sum(case when fn='c' then 1 else 0 end) as cc,
    'd' as d,sum(case when fn='d' then 1 else 0 end) as dc,
    'e' as e,sum(case when fn='e' then 1 else 0 end) as ec
    from t1 
      

  2.   

    Yang_(扬帆破浪) is perfect
      

  3.   

    access:
    1、
    select fn,count(*) as ccc from t1 group bu fn
    2、
    select 'a' as a,sum(iif(fn='a',1,0)) as ac 
    'b' as b,sum(iif(fn='b',1,0)) as bc,
    'c' as c,sum(iif(fn='c',1,0)) as cc,
    'd' as d,sum(iif(fn='d',1,0)) as dc,
    'e' as e,sum(iif(fn='e',1,0)) as ec
    from t1 
      

  4.   

    Yang_(扬帆破浪) 无愧 "星级回复"
      

  5.   

    to: playyuer(小干部) 喂老大,如果fn的值域未知呢?
      

  6.   

    oracle:
    1、
    select fn,count(fn) as ccc from t1 group bu fn;
    2、
    select 'a' as a,sum(decode(fn,'a',1,0)) as ac 
    'b' as b,sum(decode(fn,'b',1,0)) as bc,
    'c' as c,sum(decode(fn,'c',1,0)) as cc,
    'd' as d,sum(decode(fn,'d',1,0)) as dc,
    'e' as e,sum(decode(fn,'e',1,0)) as ec
    from t1 
      

  7.   

    仔细看题!可编程凑动态 SQL
      

  8.   

    Yang_(扬帆破浪) very good!!
      

  9.   

    to:bitsoft(我来也) 
    第一问一样,
    第二问看:
    http://www.csdn.net/expert/topic/508/508081.xml?temp=7.961673E-02
      

  10.   

    第三问:
    加上百分比统计:5行:
    a,7,10%
    b,3,XX%1行:
    a,7,XX%,b,3,XX%,.....
      

  11.   

    飄香兄 & playyuer(小干部) :
      过奖!
      

  12.   

    只写access 的了:
    select fn,ccc,ccc/sum(ccc) as p from
    (
    select fn,count(*) as ccc from t1 group bu fn
    ) as a2、
    select 'a' as a,sum(iif(fn='a',1,0)) as ac,sum(iif(fn='a',1,0))/count(*) as ap, 
    'b' as b,sum(iif(fn='b',1,0)) as bc,sum(iif(fn='b',1,0))/count(*) as bp, 
    'c' as c,sum(iif(fn='c',1,0)) as cc,sum(iif(fn='c',1,0))/count(*) as cp, 
    'd' as d,sum(iif(fn='d',1,0)) as dc,sum(iif(fn='d',1,0))/count(*) as dp, 
    'e' as e,sum(iif(fn='e',1,0)) as ec,sum(iif(fn='e',1,0))/count(*) as ep
    from t1 
      

  13.   

    to: Yang_(扬帆破浪) xiexie,不过我看也没那么麻烦,既然不能一言以蔽之,那方法很多喽
      

  14.   

    Yang_(扬帆破浪) ,高手,以后多关照
      

  15.   

    Yang_(扬帆破浪),GOOD  小弟得向您好好学习
      

  16.   

    to: Yang_(扬帆破浪) 错了!
    再想想!
      

  17.   

    to: bitsoft(我来也) 
     方法很多是很多,那个贴是比较通用的方法。
      

  18.   

    to: Yang_(扬帆破浪) 错了!
    再想想!
      

  19.   

    还是写sql server吧:
    1、
    select fn,ccc,convert(varchar(10),(convert(numeric(10,2),ccc/sum(ccc)*100))+'%' as p from
    (
    select fn,count(*) as ccc from t1 group bu fn
    ) as a第二问也一样用convert格式化,格式化不一定要放在SQL 语句里,在客户端处理也不错。
      

  20.   

    select fn,count(*) as ccc,convert(numeric(10,2),count(*))/(select count(*) from t1) from t1 group by fn
      

  21.   

    第二问的分母是对的,但都需要用convert转换,否则结果不对
      

  22.   

    sorry,在这里贴个与本主题无关的帖子,实在没办法,问题还没解决,我看这个帖子好多高手在关注,所以问问:怎样在image控件里显示internet上的图片(知道路径和图片名)或怎么下载到本地硬盘。
    谢谢了!
      

  23.   

    我也有,请playyuer(小干部)评价!!!一定要看!!!我测过了!!!第一问:
    Select Fn,Count(*) as Nums From T1 Group by Fn第二问:
    select 'a' as a,(Select Count(*) from T1 where Fn='a') as anum,'b' as b,(Select Count(*) from T1 where Fn='b') as bnum,'c' as c,(Select Count(*) from T1 where Fn='c') as cnum,'d' as d,(Select Count(*) from T1 where Fn='d') as dnum,'e' as e,(Select Count(*) from T1 where Fn='e') as enum第三问:
    select fn,nums,cast(cast(nums/cast((Select Count(*) from T1) as decimal(8,2)) as decimal(8,2))*100 as nvarchar(5))+'%' from (Select Fn,Count(*) as Nums From T1 Group by Fn) as T2select 'a' as a,(Select Count(*) from T1 where Fn='a') as anum,
    cast(cast(cast((Select Count(*) from T1 where Fn='a') as decimal(8,2))/cast((Select Count(*) from T1) as decimal(8,2)) as decimal(8,2))*100 as nvarchar(5)) + '%' as ap,
    'b' as b,(Select Count(*) from T1 where Fn='b') as bnum,
    cast(cast(cast((Select Count(*) from T1 where Fn='b') as decimal(8,2))/cast((Select Count(*) from T1) as decimal(8,2)) as decimal(8,2))*100 as nvarchar(5)) + '%' as bp,
    'c' as c,(Select Count(*) from T1 where Fn='c') as cnum,
    cast(cast(cast((Select Count(*) from T1 where Fn='c') as decimal(8,2))/cast((Select Count(*) from T1) as decimal(8,2)) as decimal(8,2))*100 as nvarchar(5)) + '%' as cp,
    'd' as d,(Select Count(*) from T1 where Fn='d') as dnum,
    cast(cast(cast((Select Count(*) from T1 where Fn='d') as decimal(8,2))/cast((Select Count(*) from T1) as decimal(8,2)) as decimal(8,2))*100 as nvarchar(5)) + '%' as dp,
    'e' as e,(Select Count(*) from T1 where Fn='e') as enum,
    cast(cast(cast((Select Count(*) from T1 where Fn='e') as decimal(8,2))/cast((Select Count(*) from T1) as decimal(8,2)) as decimal(8,2))*100 as nvarchar(5)) + '%' as ep