我有一个海外同事的 sql 语句,但是当我尝试运行它时弹出一个框,上面写着“输入替换变量”。我在里面放什么?我的同事说他们没有得到同一个盒子。是什么导致此消息?我在下面提供声明。任何帮助是极大的赞赏。
此外,第三行给出了一条消息,指出缺少右括号。
select SUBSTR(created_ts, 1, 7) as created_month,
count(t1.id) as mops_created,
count(completed_ts <> '') as num_complete,
round(AVG(DATEDIFF(planning_complete_ts, created_ts)), 1) as average_created_to_planning_complete,
round(AVG(DATEDIFF(review_complete_ts, planning_complete_ts)), 1) as average_planning_complete_to_review_complete,
round(AVG(DATEDIFF(scheduling_complete_ts, planning_complete_ts)), 1) as average_planning_complete_to_scheduling_complete,
round(AVG(DATEDIFF(scheduled_ts, scheduling_complete_ts)), 1) as average_scheduled_for_x_days_out,
round(AVG(DATEDIFF(completed_ts, planning_complete_ts)), 1) as average_planning_complete_to_mop_complete,
round(AVG(planning_complete_num), 1) as average_num_times_planning_complete,
max(planning_complete_num) as max_planning_complete,
round(AVG(scheduling_complete_num), 1) as average_num_time_scheduled,
max(scheduling_complete_num) as max_scheduled_num
FROM
(select a.id, a.created_ts, a.scheduled_ts, work_start_ts, completed_ts
from TRAFFIC_ENG.DSIS_CC_MASTER as a
WHERE
a.created_ts >= '2013-01-01 00:00:00'
AND
a.status_cc_options_id NOT IN (810, 820)) as t1
LEFT JOIN
(select a.id, max(c.orig_date) as review_complete_ts
from
TRAFFIC_ENG.DSIS_CC_MASTER as a
INNER JOIN
TRAFFIC_ENG.DSIS_CC_LOG_NOTE as c
ON c.cc_master_id = a.id
AND (c.cc_log_note_type_id = 8 OR c.note = 'Passed Review & submitted to Scheduling')
WHERE
a.created_ts >= '2013-01-01 00:00:00'
AND
a.status_cc_options_id NOT IN (810, 820)
GROUP BY a.id) as review_complete
ON review_complete.id = t1.id
LEFT JOIN
(
select a.id, min(c.orig_date) as planning_complete_ts
from
TRAFFIC_ENG.DSIS_CC_MASTER as a
INNER JOIN
TRAFFIC_ENG.DSIS_CC_LOG_NOTE as c
ON c.cc_master_id = a.id
AND (c.cc_log_note_type_id = 5 OR c.note = 'Submitted for Review')
WHERE
a.created_ts >= '2013-01-01 00:00:00'
AND
a.status_cc_options_id NOT IN (810, 820)
GROUP BY a.id
) as planning_complete
ON planning_complete.id = t1.id
LEFT JOIN
(
select a.id, (c.orig_date) as scheduling_complete_ts
from
TRAFFIC_ENG.DSIS_CC_MASTER as a
INNER JOIN
TRAFFIC_ENG.DSIS_CC_LOG_NOTE as c
ON c.cc_master_id = a.id
AND (c.cc_log_note_type_id = 7 OR c.note='Scheduled')
WHERE
a.created_ts >= '2013-01-01 00:00:00'
AND
a.status_cc_options_id NOT IN (810, 820)
GROUP BY a.id
) as scheduling_complete
ON scheduling_complete.id = t1.id
LEFT JOIN
(
select a.id, count(c.orig_date) as planning_complete_num
from
TRAFFIC_ENG.DSIS_CC_MASTER as a
INNER JOIN
TRAFFIC_ENG.DSIS_CC_LOG_NOTE as c
ON c.cc_master_id = a.id
AND (c.cc_log_note_type_id = 5 OR c.note = 'Submitted for Review')
WHERE
a.created_ts >= '2013-01-01 00:00:00'
AND
a.status_cc_options_id NOT IN (810, 820)
GROUP BY a.id
) as planning_complete_num
ON planning_complete_num.id = t1.id
LEFT JOIN
(
select a.id, count(c.orig_date) as scheduling_complete_num
from
TRAFFIC_ENG.DSIS_CC_MASTER as a
INNER JOIN
TRAFFIC_ENG.DSIS_CC_LOG_NOTE as c
ON c.cc_master_id = a.id
AND (c.cc_log_note_type_id = 7 OR c.note='Scheduled')
WHERE
a.created_ts >= '2013-01-01 00:00:00'
AND
a.status_cc_options_id NOT IN (810, 820)
GROUP BY a.id
) as scheduling_complete_num
ON scheduling_complete_num.id = t1.id
GROUP BY created_month