总计、间接和直接表以及从“摘要”中提取数据。最后一张表“int_data”是从“aspect_summary”中拉出来的……我不能让它和其他人一起玩得很好。我的查询只给了我 1 行结果,我不知道为什么。建议?
SELECT user,
amin,
COALESCE(sum(tavg*tcomp)) AS d_task_min,
COALESCE(indirect.iminutes,0) AS i_task_min,
COALESCE(((amin)+(indirect.iminutes)/60),0) AS FAKE_d_call_hour,
COALESCE(tcomp*tavg,0) + COALESCE(indirect.iminutes,0) AS totals,
hrs_earned,
hrs_equiv,
minutes,
diff,
COALESCE(SUM(tot_rec_tasks)-sum(tot_i_tasks),0) AS tot_d_tasks,
COALESCE(tot_i_tasks,0) AS tot_i_tasks,
int_id,
ROUND(COALESCE((((amin-(sum(indirect.iminutes)))/60)+ (sum(indirect.iminutes)/60)),0),2) AS ttime2,
ROUND(COALESCE((hrs_earned / (((amin-(sum(indirect.iminutes)))/60)+ (sum(indirect.iminutes)/60)))*100,0),2) AS prod,
ROUND((COALESCE((hrs_earned / hrs_equiv),0)*100),2) AS eff,
ROUND(COALESCE(hrs_earned/(((amin-(sum(indirect.iminutes)))/60)+ (sum(indirect.iminutes)/60)),0)*100,2) AS util,
amin AS aspect_time
FROM
(
SELECT
U.user_name AS user,
U.user_id AS tuser_id,
M.minutes AS tminutes,
ta.task_type AS ttasktype,
ta.task_average as tavg,
tc.completed as tcomp,
ROUND(SUM((((TA.task_average)*TC.completed))/60),2) AS ttime,
ROUND(SUM((((TA.task_average)*TC.completed))/60),2) AS hrs_earned,
ROUND(SUM(((TA.task_average/6)*TC.completed)),2) AS hrs_equiv,
ROUND(SUM(M.minutes/60),2) AS minutes,
ROUND((SUM(M.minutes)/60),2)-ROUND(SUM((TA.task_average*TC.completed)/60),2) AS diff,
SUM(TC.completed) AS tot_rec_tasks
FROM summary S
JOIN users U
ON U.user_id = S.user_id
JOIN minutes M
ON M.minutes_id = S.minutes_id
JOIN tcompleted TC
ON TC.tcompleted_id = S.tcompleted_id
JOIN tasks TA
ON TA.task_id = S.task_id
JOIN hour_interval H
ON H.hourinterval_id = S.hourinterval_id
AND DATE(submit_date) = curdate()
AND TIME(submit_date) BETWEEN '00:00:00' and '23:59:59'
GROUP BY tuser_id) AS total
LEFT JOIN
(SELECT U.user_id AS iuser_id, M.minutes AS iminutes, tc.completed AS tot_i_tasks
FROM summary S
JOIN users U
ON U.user_id = S.user_id
JOIN minutes M
ON M.minutes_id = S.minutes_id
JOIN tasks TA
ON TA.task_id = S.task_id
JOIN tcompleted TC
ON TC.tcompleted_id = S.tcompleted_id
WHERE TA.task_type='indirect'
AND DATE(submit_date) = curdate()
AND TIME(submit_date) BETWEEN '00:00:00' and '23:59:59'
GROUP BY iuser_id) AS indirect
ON tuser_id = iuser_id
LEFT JOIN
(SELECT U.user_id AS duser_id
FROM summary S
JOIN users U
ON U.user_id = S.user_id
JOIN minutes M
ON M.minutes_id = S.minutes_id
JOIN tcompleted TC
ON TC.tcompleted_id = S.tcompleted_id
JOIN tasks TA
ON TA.task_id = S.task_id
WHERE TA.task_type='direct'
AND DATE(submit_date) = curdate()
AND TIME(submit_date) BETWEEN '00:00:00' and '23:59:59'
GROUP BY duser_id) AS direct
ON tuser_id = duser_id
LEFT JOIN
(Select U.user_id AS int_id, SUM(M.minutes) AS amin
FROM aspect_summary A
JOIN users U ON U.user_id = A.user_id
JOIN minutes M ON M.minutes_id = A.minutes_id
JOIN hour_interval H ON H.hourinterval_id = A.hourinterval_id
AND DATE(submit_date) = curdate()
AND TIME(submit_date) BETWEEN '00:00:00' and '23:59:59'
GROUP BY int_id) AS int_data
ON tuser_id = int_id