很抱歉这个模糊的问题。我只是不知道如何以一种简洁的方式进行解释。
我正在尝试运行将每个作业ID的job_modules
分组的查询。问题在于表中有许多job_dis
,而单个job_modules
中有许多job_id
。我只是不知道如何做一个小组。
这就是job_id
的样子。表格中有多个job_id
,但我想将模块分组。
|job_Module_____________|AVG_REC__|JOB_ID__
|DataSelectionProcess |0.017 |32681
|DataSelectionProcess |0.002 |32681
|DataSelectionProcess |0 |32681
|DataSelectionProcess |0.015 |32681
|DataSelectionProcess |0.004 |32681
|DataSelectionProcess |0.009 |32681
|DataSelectionProcess |0.002 |32681
|DataSelectionProcess |0.791 |32681
|DataSelectionProcess |0.001 |32681
|DataSelectionProcess |0 |32681
|DataSelectionProcess |0.002 |32681
|DataSelectionProcess |2.14 |32681
|OutputFileProcess |1.926 |32681
|OutputFileProcess |0.044 |32681
|OutputFileProcess |0.001 |32681
|OutputFileProcess |0.00305 |32681
|OutputFileProcess |0.00102 |32681
|OutputFileProcess |0 |32681
|OutputFileProcess |0.00609 |32681
|RecallMatchCodeProcess |44.16148 |32681
以下是预期结果,应该将所有avg_rec时间加在一起,并添加所有模块:
|job_Module_____________|AVG_REC__|JOB_ID__
|DataSelectionProcess |3.017 |32681
|OutputFileProcess |2.006 |32681
|RecallMatchCodeProcess |44.16148 |32681
这是我要运行的查询。
Select job_module, AVG_REC_TIME_MILLIS, job_id
FROM job_step
where job_id ='32681' or
job_id ='32687' or
job_id ='32714' or
job_id ='32716' or
job_id ='32723' or
job_id ='32743' or
job_id ='32758' or
job_id ='32767' or
job_id ='32768' or
job_id ='32782' or
job_id ='32784' or
job_id ='32800' or
job_id ='32801' or
job_id ='32849' or
job_id ='32851' or
job_id ='32884' or
job_id ='32913' or
job_id ='32928' or
job_id ='32938' or
job_id ='32947' or
job_id ='33089' or
job_id ='33095'
group by job_module
ORDER BY JOB_ID;
答案 0 :(得分:3)
我认为您需要按job_id
和job_module
进行分组,如:
select job_id, job_module, sum(AVG_REC_TIME_MILLIS)
from job_step
where job_id in (
'32681', '32687', '32714', '32716', '32723',
'32743', '32758', '32767', '32768', '32782',
'32784', '32800', '32801', '32849', '32851',
'32884', '32913', '32928', '32938', '32947',
'33089', '33095'
)
group by job_id, job_module
答案 1 :(得分:0)
我认为AVG_REC 时间以秒和毫秒为单位。在这种情况下,您需要正确地汇总时间-通过将小数部分除以1000并用秒求和,将毫秒转换为秒。看起来像这样:
SELECT job_id, job_module,
NUMTODSINTERVAL(SUM(
SUBSTR(avg_rec_time_millis, 1, instr(avg_rec_time_millis, '.')-1) +
(SUBSTR(avg_rec_time_millis, instr(avg_rec_time_millis, '.')+1)/1000)
)
, 'SECOND') sum_time
FROM job_step
WHERE job_id IN (
'32681', '32687', '32714', '32716', '32723','32743', '32758', '32767', '32768', '32782', '32784',
'32800', '32801', '32849', '32851','32884', '32913', '32928', '32938', '32947', '33089', '33095'
)
GROUP BY job_id, job_module;