select 分公司, sum(服务器), sum(网络设备) from 表 group by 分公司
提示我“ORA-01722:无效数字”
他写的很对的!!!!是你的sql 有问题吧
SELECT 分公司,SUM('服务器'),SUM('网络设备') FROM common_view GROUP BY 分公司
把表结构和你的SQL贴出来看看
select 分公司, sum(decode(设备类型,'服务器',1,null)) as "服务器", sum(decode(设备类型,'网络设备',1,null)) as "网络设备" from 表 group by 分公司
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
from 表
group by 分公司
sum(decode(设备类型,'服务器',1,null)) as "服务器",
sum(decode(设备类型,'网络设备',1,null)) as "网络设备"
from 表
group by 分公司
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
Linux技术交流群112743374,45211651 112653122 57703664
sum(decode(设备类型,'服务器',1,null)) as "服务器",
sum(decode(设备类型,'网络设备',1,null)) as "网络设备"
from 表
group by 分公司