我有一个SQL表(Oracle和DB2),其中包含来自许多服务器的进程统计信息。为了简单起见,我们可以说:
Timestamp | Server | PID | Command_line | CPU_Usage
1385101402, hosta, 489, init, 0.3
1385101399, hosta, 264, perl test.pl, 32
1385102402, hosta, 489, init, 0.3
1385102399, hosta, 264, perl test.pl, 22
1385103402, hosta, 489, init, 0.3
1385103402, hostb, 489, init, 0.2
1385103399, hosta, 264, perl test.pl, 17
1385104402, hosta, 489, init, 0.1
1385104402, hostb, 489, init, 0.2
1385104399, hosta, 264, perl test.pl, 4
1385105402, hosta, 489, init, 0.3
1385105402, hostc, 489, init, 0.3
1385105399, hosta, 264, perl test.pl, 42
1385106402, hosta, 489, init, 0.5
1385106399, hosta, 264, perl test.pl, 52
我想制作一张有意义的图表,但你可以想象这张表很大。所以我想要做的只是提取超过50%CPU的进程的详细信息。对于数据点(WHERE“CPU_Usage”> 50)很容易做到这一点但当然只有当它们高于50%时才会显示它们,之前的历史记录和50%以下的后续性能都不能生成图表。
我想要的是任何PID + Command_Line tupple,发现超过50%的CPU会获取所有可用的数据。所以在这个例子中,我希望过程的所有样本都包含PID 264,因为它超出了阈值。其余的我想忽略
答案 0 :(得分:2)
查看oracle的工作demo。我不确定DB2。
WITH DATASET
AS (SELECT 489 AS PID, 0.3 AS PERCENTAGES FROM DUAL UNION ALL
SELECT 264 AS PID, 32 AS PERCENTAGES FROM DUAL UNION ALL
SELECT 489 AS PID, 0.3 AS PERCENTAGES FROM DUAL UNION ALL
SELECT 264 AS PID, 22 AS PERCENTAGES FROM DUAL UNION ALL
SELECT 489 AS PID, 0.3 AS PERCENTAGES FROM DUAL UNION ALL
SELECT 489 AS PID, 0.2 AS PERCENTAGES FROM DUAL UNION ALL
SELECT 264 AS PID, 17 AS PERCENTAGES FROM DUAL UNION ALL
SELECT 489 AS PID, 0.1 AS PERCENTAGES FROM DUAL UNION ALL
SELECT 489 AS PID, 0.2 AS PERCENTAGES FROM DUAL UNION ALL
SELECT 264 AS PID, 4 AS PERCENTAGES FROM DUAL UNION ALL
SELECT 489 AS PID, 0.3 AS PERCENTAGES FROM DUAL UNION ALL
SELECT 489 AS PID, 0.3 AS PERCENTAGES FROM DUAL UNION ALL
SELECT 264 AS PID, 42 AS PERCENTAGES FROM DUAL UNION ALL
SELECT 489 AS PID, 0.5 AS PERCENTAGES FROM DUAL UNION ALL
SELECT 264 AS PID, 52 AS PERCENTAGES FROM DUAL)
SELECT
*
FROM
DATASET B
WHERE
B.PID IN (SELECT
A.PID
FROM
DATASET A
WHERE
A.PERCENTAGES > 50)