I ran bellowing query;
Query:
SELECT j.jobId,
j.productId,
p.productUnitPrice
FROM JobRequiredProducts J
JOIN Product p
ON p.productId = j.productId
WHERE j.jobId = 1
ORDER BY j.jobId
And got bellowing result;
Query result:
jobId | productId | unitPrice
_____________________________
1 | 4 | 175.99
1 | 5 | 100.00
1 | 6 | 125.00
Now, I want to calculate all unitPrice to get the total. the result I expect is;
Expecting result:
jobId | productId | Total
____________________________
1 | 4 | 175.99
1 | 5 | 100.00
1 | 6 | 125.00
null | null | 400.99
Therefor bellowing is the query I tried;
Query I tried:
SELECT j.jobId,
j.productId,
SUM(p.productUnitPrice) AS 'Total'
FROM JobRequiredProducts J
JOIN Product p
ON p.productId = j.productId
WHERE j.jobId = 1
GROUP BY j.jobId,j.productId WITH ROLLUP
But it didn't give me the result I expected, where I went wrong and what I gotta do to get the result I expect?