alexbancheva

Task9_Past Expenses_Exam_27June2020

Feb 10th, 2021
595
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Task 9 Past Expenses
  2. SELECT j.JobId, ISNULL(SUM(op.Quantity * p.Price), 0) AS Total
  3.     FROM Jobs AS j
  4.     LEFT JOIN Orders AS o ON o.JobId = j.JobId
  5.     LEFT JOIN OrderParts AS op ON op.OrderId = o.OrderId
  6.     LEFT JOIN Parts AS p ON op.PartId = p.PartId
  7.     WHERE j.[Status] = 'Finished'
  8.     GROUP BY j.JobId
  9.     ORDER BY Total DESC,
  10.                 j.JobId ASC
RAW Paste Data