0

嘿,伙计们,您介意检查我是否正确执行此操作吗?我被困在这个问题上:

生成查询以显示平均工作成本高于所有工作的平均工作成本的所有会计师的会计师姓名及其平均工作成本(四舍五入到小数点后两位)。

SELECT 
  a.name + a.surname, 
  SUM(jt.cost * (DATEDIFF(mi, time_complete, time_start))) % SUM(job_id) AS average_job_cost
FROM accountant AS a 
LEFT OUTER JOIN job AS j ON a.staff_id = j.staff_id 
LEFT OUTER JOIN job_type AS jt ON jt.job_type_id = j.job_type_id
WHERE average_job_cost > (SELECT SUM(jt.cost * (DATEDIFF(mi, time_complete, time_start))) % SUM(job_id);
4

1 回答 1

0

像这样的东西(从原始编辑到使用在其他问题上找到的client_id)

WITH jobinfo as
(
   SELECT j.client_id, AVG(jt.cost * (DATEDIFF(mi, timecomplete, timestart))) as avgerage
   FROM job as j
   JOIN job_type as jt ON j.jobtype_id = jt.jobtype_id
   GROUP BY j.client_id
), avgAll AS
(
   SELECT AVG(average) as aall
   FROM jobinfo
)
SELECT 
  c.client_id,
  c.name + c.surname, 
  c.phone, 
  c.email_address, 
  j.avgerage
FROM client as c 
JOIN jobinfo j ON c.client_id= j.client_id
WHERE j.avgerage > (SELECT aall FROM avgALL)
ORDER BY j.avgerage DESC
于 2013-11-03T17:00:34.663 回答