我不确定我的标题是否正确地描述了这个问题,但我试图做的是将错误率列表与计算的平均值和stddev结合在一起,在一个结果集中,所以它可以很容易地绘制出来。下面是有问题的查询:
select specific.POD, specific.DEFINITION, specific.error_rate as POD_JOB_RATE, general.error_rate as "General Rate for this JOB" from (
select definition, total_run,failures, round(failures/total_run,4) as error_rate from (
select
DEFINITION,
count(*) as total_run,
count(case when state in (10, 15, 19) then requestid end) as failures
from FILTERED_REQUEST_HISTORY group by DEFINITION
)) general
join (
select POD, DEFINITION, round(failures/total_run) as error_rate from (
select
POD,
DEFINITION,
count(*) as total_run,
count(case when state in (10, 15, 19) then requestid end) as failures
from FILTERED_REQUEST_HISTORY group by POD, DEFINITION
) order by POD, DEFINITION, failures/total_run, total_run desc
) specific
ON specific.DEFINITION = general.DEFINITION where specific.error_rate > general.error_rate order by POD;
字符串
它产生:
| POD|定义|POD_JOB_RATE|本POD中所有作业的一般故障率|
| --|--|--|--|
| BDN| JobDefinition://apps/crmCommon/elasticSearch/UpdateDocumentsWhoseReferenceableContentHasChangedForcityJobDef| 1 |零点四八|
| BDN| JobDefinition://apps/crmCommon/elasticSearch/IndexActiveMetaModelVersionJobDef| 1 |零点四八|
| Bon| JobDefinition://bip/bipJob|七七四二|0.0103|
| Bry|作业定义://apps/psc/techStack/functionalSecurity/PscSecurityUpdateCredentialJob| 0.0769|零点零零五|
| Bry| JobDefinition://apps/sales/salesForecasting/forecasts/RefreshForecast| 1 |零点零零五|
| BUN|作业定义://apps/hcm/person/search/PersonKeywordSearch|零点七五五|零点零零一|
| CAAS| JobDefinition://apps/sales/salesForecasting/forecasts/DueDateTime| 1 |零点零零八|
| CAAS| JobDefinition://apps/sales/salesForecasting/forecasts/RefreshForecast| 1 |零点零零八|
| CACG| JobDefinition://apps/sales/salesForecasting/forecasts/RefreshForecast| 1 |0.0004|
| CADM| JobDefinition://apps/sales/salesForecasting/forecasts/RefreshForecast| 1 |0.0003|
下面是确定avg
和stddev
的查询
select avg(error_rate), stddev(error_rate) from (
select failures/total_run as error_rate from (
select
DEFINITION,
count(*) as total_run,
count(case when state in (10, 15, 19) then requestid end) as failures
from FILTERED_REQUEST_HISTORY group by DEFINITION
)
) avg_error_rate_by_jd;
型
制作:
| ROUND(AVG(ERROR_RATE),4)|ROUND(STDDEV(ERROR_RATE),4)|
| --|--|
| 零点零零三|零点四二|
我想要的是:
| POD|定义|POD_JOB_RATE|本POD中所有作业的一般故障率|avg(所有pod)|stddev(所有pod)|
| --|--|--|--|--|--|
| BDN| JobDefinition://apps/crmCommon/elasticSearch/UpdateDocumentsWhoseReferenceableContentHasChangedForcityJobDef| 1 |零点四八|零点零零三|零点四二|
| BDN| JobDefinition://apps/crmCommon/elasticSearch/IndexActiveMetaModelVersionJobDef| 1 |零点四八|零点零零三|零点四二|
| Bon| JobDefinition://bip/bipJob|七七四二|0.0103|零点零零三|零点四二|
| Bry| JobDefinition://apps/sales/salesForecasting/forecasts/RefreshForecast| 0.0769|零点零零五|零点零零三|零点四二|
| CAAS| JobDefinition://apps/sales/salesForecasting/forecasts/DueDateTime| 1 |零点零零八|零点零零三|零点四二|
| CAAS| JobDefinition://apps/sales/salesForecasting/forecasts/RefreshForecast|零点七五五|零点零零八|零点零零三|零点四二|
| CACG| JobDefinition://apps/sales/salesForecasting/forecasts/RefreshForecast| 1 |0.0004|零点零零三|零点四二|
| CADM| JobDefinition://apps/sales/salesForecasting/forecasts/RefreshForecast| 1 |0.0003|零点零零三|零点四二|
| CADZ| JobDefinition://apps/sales/salesForecasting/forecasts/RefreshForecast| 1 |0.0032|零点零零三|零点四二|
| CADZ|作业定义://apps/crmCommon/core/standardImport/StandardImportMasterJob| 1 |0.0032|零点零零三|零点四二|
我觉得这是一种特殊的加入,但我可以完全关闭。
2条答案
按热度按时间okxuctiv1#
最简单的方法是
CROSS JOIN
,因为整体计算的结果是单行,这不会乘以最终的行数,而是将两个想要的列添加到每行中。字符串
nb不要在子查询中使用order by,这是浪费精力,只需使用最后的order by来控制结果顺序。
另外:你可以使用“窗口函数”来简化你的查询,例如:
型
甚至可以将其组合以减少数据的传递:
型
引入ps
* 1.0
以确保十进制结果pvabu6sv2#
不要使用
JOIN
,使用解析函数来执行“一般”计算,并计算平均值和标准差:字符串
或者,您可以完全使用分析函数(而不使用聚合函数):
型
fiddle