我正在尝试将这两个查询结合起来,但不确定到底如何。我想我可能需要使用内部联接或左联接,但不确定其语法。
SELECT job_ID, SUM(AVG_REC_TIME_MILLIS), SUM(Record_count)
FROM job_step js
GROUP BY js.JOB_ID;
SELECT job_id,start_dts FROM job
WHERE start_dts BETWEEN '27-JAN-04' AND '17-MAR-05';
答案 0 :(得分:2)
SELECT js.job_ID, j.start_dts, SUM(js.AVG_REC_TIME_MILLIS), SUM(js.Record_count)
FROM job_step js
LEFT JOIN job j ON j.job_id = js.job_ID
GROUP BY js.JOB_ID, j.start_dts
WHERE j.start_dts BETWEEN '27-JAN-04' AND '17-MAR-05';
答案 1 :(得分:1)
我想你想要
SELECT j.job_id, MIN(j.start_dts) as start_dts,
SUM(js.AVG_REC_TIME_MILLIS), SUM(js.Record_count)
FROM job j JOIN
job_step js
WHERE j.start_dts BETWEEN DATE '2004-01-27' AND DATE '2005-03-17'
GROUP BY j.job_id;
注意:
LEFT JOIN
中的第一张表。date
关键字是包含日期常量的更好方法;例如,它使用ISO 8601标准日期格式。