You don't specify the database you are using, but many databases support the with rollup
clause for the group by
:
SELECT oi.PurchaseID,
SUM(oi.Quanity * CONVERT(decimal(18,2), p.ItemPrice)) AS sub_total
FROM vwPurchaseType oi JOIN
tblColor p
ON p.ColorID = oi.ColorID
WHERE oi.UserID = 1
GROUP BY oi.PurchaseID WITH ROLLUP;
This will add an additional row where the PurchaseId
is NULL
. That has the total in it.