一张表中有分公司,设备类型两列(当然还有其他列)
想按照分公司统计各个设备类型的记录条数。如下:分公司    服务器   网络设备
北京       10        12
上海       12        21
天津       12        14
请问这个sql语句怎么写?

解决方案 »

  1.   

    select 分公司, sum(服务器), sum(网络设备)
    from 表
    group by 分公司
      

  2.   

    提示我“ORA-01722:无效数字”
      

  3.   

    他写的很对的!!!!是你的sql 有问题吧
      

  4.   

    SELECT 分公司,SUM('服务器'),SUM('网络设备') FROM common_view GROUP BY 分公司
      

  5.   

    把表结构和你的SQL贴出来看看
      

  6.   

    select 分公司, 
    sum(decode(设备类型,'服务器',1,null)) as "服务器",
    sum(decode(设备类型,'网络设备',1,null)) as "网络设备"
    from 表
    group by 分公司
      

  7.   


    with tmp as
    (
    select '北京' fgs, '服务器' sblx from dual
    union all
    select '北京' fgs, '网络设备' sblx from dual
    union all
    select '北京' fgs, '服务器' sblx from dual
    union all
    select '上海' fgs, '服务器' sblx from dual
    union all
    select '上海' fgs, '网络设备' sblx from dual
    union all
    select '天津' fgs, '网络设备' sblx from dual
    union all
    select '天津' fgs, '服务器' sblx from dual
    )
    select fgs, 
    sum(decode(sblx,'服务器',1,null)) "服务器",
    sum(decode(sblx,'网络设备',1,null)) "网络设备"
    from tmp
    group by fgs;FGS              服务器       网络设备
    --------- ---------- ----------
    天津                 1          1
    上海                 1          1
    北京                 2          1
      

  8.   

    解决了没有啊,要是在还没有的话。到这里问问
    Linux技术交流群112743374,45211651  112653122  57703664
      

  9.   

    谢谢大家,问题已经解决用的是如下sqlselect 分公司,  
    sum(decode(设备类型,'服务器',1,null)) as "服务器",
    sum(decode(设备类型,'网络设备',1,null)) as "网络设备"
    from 表
    group by 分公司