SELECT tic.DATE AS submit_date
,sum(tic.issues_created) AS issues_created
,COALESCE(sum(y.issues_closed), 0) AS issues_closed
,sum(CASE
WHEN tic.action = 1
THEN 1
ELSE 0
END) AS issues_routed
,COALESCE(y.issue_r_acc, 0) AS issue_r_acc
,COALESCE(y.accuracy, 0) AS issue_r_acccy
,sum(CASE
WHEN tic.action = 2
THEN 1
ELSE 0
END) AS issue_rec
,sum(CASE
WHEN tic.action = 3
THEN 1
ELSE 0
END) AS issue_ig
FROM (
SELECT d.DATE
,count(x.incident_id) AS issues_created
,x.action
FROM (
SELECT to_char(date_trunc('day', ((CURRENT_DATE - 1) - offs)), 'YYYY-MM-DD') AS DATE
FROM generate_series(0, 6, 1) AS offs
) d
LEFT OUTER JOIN (
SELECT *
FROM incident
WHERE id = 100
) x ON (d.DATE = to_char(date_trunc('day', x.submit_date), 'YYYY-MM-DD'))
GROUP BY d.DATE
,x.submit_date
,x.action
ORDER BY d.DATE DESC
) AS tic
LEFT OUTER JOIN (
SELECT submit_date
,number_of_match_incidents AS issue_r_acc
,number_of_incidents AS issues_closed
,number_of_match_incidents / number_of_incidents AS accuracy
FROM pred
WHERE id = 100
AND type = 1
AND label = 'ABC'
) y ON (tic.DATE = to_char(date_trunc('day', y.submit_date), 'YYYY-MM-DD'))
GROUP BY tic.DATE
,tic.issues_created
,COALESCE(y.issue_r_acc, 0)
,COALESCE(y.issues_closed, 0)
,COALESCE(y.accuracy, 0)
ORDER BY tic.DATE DESC
我需要在7天的时间内从事件表和其他列中得到所有事件总和(tic.issues_created)的总和。
但我面临的问题是因为我必须通过行动来订购它,因此它会使总事件数不正确。
我错过了什么?