需求如下:
log表
id host name content status date
1 web主机 cpu使用率 cpu使用率5% 正常 2009-8-6
2 web主机 内存使用率 内存使用率20% 正常 2009-8-6
3 web主机 空间使用率 空间使用率39% 正常 2009-8-6
4 业务主机 cpu使用率 cpu使用率5% 正常 2009-8-6
5 业务主机 内存使用率 内存使用率20% 正常 2009-8-6
6 业务主机 空间使用率 空间使用率39% 正常 2009-8-6
7 接口主机 cpu使用率 cpu使用率5% 正常 2009-8-6
8 接口主机 内存使用率 内存使用率20% 正常 2009-8-6
9 接口主机 空间使用率 空间使用率39% 正常 2009-8-6
希望能统计处如下结果web主机状态 cup使用率 内存使用率 业务主机状态 cup使用率 内存使用率 接口主机状态 cup使用率 内存使用率
正常 cpu使用率5% 内存使用率20% 正常 cpu使用率5% 内存使用率20% 正常 cpu使用率5% 内存使用率20%各位大侠,如何实现?
log表
id host name content status date
1 web主机 cpu使用率 cpu使用率5% 正常 2009-8-6
2 web主机 内存使用率 内存使用率20% 正常 2009-8-6
3 web主机 空间使用率 空间使用率39% 正常 2009-8-6
4 业务主机 cpu使用率 cpu使用率5% 正常 2009-8-6
5 业务主机 内存使用率 内存使用率20% 正常 2009-8-6
6 业务主机 空间使用率 空间使用率39% 正常 2009-8-6
7 接口主机 cpu使用率 cpu使用率5% 正常 2009-8-6
8 接口主机 内存使用率 内存使用率20% 正常 2009-8-6
9 接口主机 空间使用率 空间使用率39% 正常 2009-8-6
希望能统计处如下结果web主机状态 cup使用率 内存使用率 业务主机状态 cup使用率 内存使用率 接口主机状态 cup使用率 内存使用率
正常 cpu使用率5% 内存使用率20% 正常 cpu使用率5% 内存使用率20% 正常 cpu使用率5% 内存使用率20%各位大侠,如何实现?
解决方案 »
- 视图调用
- 求解:SQL*Loader-522: lfiopn failed for file (ldr_case2.log)
- 修改oracle参数中的pga_aggregate_target是否有风险?
- imp导入单张表的问题
- imp导入出错:不是有效的导出文件,标题验证失败
- 帮我分析一下这个表的结构,谢谢
- 服务器升级后的内存划分(pga、sga),另数据库记录大量照片,表空间满后删除部分照片,仍不能插入新数据(含照片),如何解决?表空间释放问题……
- 【 软 件 架 构 研 讨 会】
- 存储过程问题 300分 在线等待
- 求大神给个sql优化或解决方案
- OCI与oracle times ten 选择问题
- 求助:关于LINUX SHELL接受存储过程OUT参数
max(case when host='web主机' and rn=1 then content end ) cpu使用率,
max(case when host='web主机' and rn=2 then content end ) 内存使用率,
decode(max(case when host='业务主机' and status<>'正常' then status end),null,'正常','不正常') 业务主机状态,
max(case when host='业务主机' and rn=1 then content end) cpu使用率,
max(case when host='业务主机' and rn=2 then content end) 内存使用率,
decode(max(case when host='接口主机' and status<>'正常' then status end),null,'正常','不正常') 接口主机状态,
max(case when host='接口主机' and rn=1 then content end) cpu使用率,
max(case when host='接口主机' and rn=2 then content end) 内存使用率 from(
select row_number()over(partition by host order by id) rn,
host,name,content,status from test_h)--测试通过
ID HOST NAME CONTENT STATUS
1 web主机 cpu使用率 cpu使用率5% 正常
2 web主机 内存使用率20% 正常
3 web主机 空间使用率39% 正常
4 业务主机 cpu使用率5% 正常
5 业务主机 内存30% 正常
6 业务主机 空间3% 正常
7 接口主机 cpu 2% 正常
8 接口主机 内存4% 不正常WEB主机状态 CPU使用率 内存使用率 业务主机状态 CPU使用率 内存使用率 接口主机状态 CPU使用率 内存使用率
正常 cpu使用率5% 内存使用率20% 正常 cpu使用率5% 内存30% 不正常 cpu 2% 内存4%
当然也可以用存储过程实现。
那是因为你要的结果字段很多。不过都大同小异,那几个case其实也就换个参数而已
a.date "日期",
case when ws=3 then '正常' else '不正常' end "web主机状态",
ws1 "cpu使用率",
ws2 "内存使用率",
ws3 "空间使用率",
case when bs=3 then '正常' else '不正常' end "业务主机状态",
ws1 "cpu使用率",
ws2 "内存使用率",
ws3 "空间使用率",
case when is_=3 then '正常' else '不正常' end "接口主机状态",
ws1 "cpu使用率",
ws2 "内存使用率",
ws3 "空间使用率"
from (
select date,
sum(case when host='web主机' and status='正常' then 1 else 0 end) ws,
max(case when host='web主机' and name='cpu使用率' then content else '' end) ws1,
max(case when host='web主机' and name='内存使用率' then content else '' end) ws2,
max(case when host='web主机' and name='空间使用率' then content else '' end) ws3,sum(case when host='业务主机' and status='正常' then 1 else 0 end) bs,
max(case when host='业务主机' and name='cpu使用率' then content else '' end) bs1,
max(case when host='业务主机' and name='内存使用率' then content else '' end) bs2,
max(case when host='业务主机' and name='空间使用率' then content else '' end) bs3, sum(case when host='接口主机' and status='正常' then 1 else 0 end) is_,
max(case when host='接口主机' and name='cpu使用率' then content else '' end) is1,
max(case when host='接口主机' and name='内存使用率' then content else '' end) is2,
max(case when host='接口主机' and name='空间使用率' then content else '' end) is3from machine_status group by date) a