SQL Grouping Sets

–**********************
— GROUPING SETS
–**********************

select ProductName, invoiceId, custid, sum(quan * p.cost) as QuantitySum
from product as p join invoice as i on i.ProductId = p.ProductId AND p.productid = 4 Group by p.productname, invoiceid, custid

select p.ProductName, sum(quan * p.cost) as QuantitySum
from product as p join invoice as i on i.ProductId = p.ProductId AND p.productid = 4 Group by p.productname

select p.ProductName, i.invoiceid, custid, sum(quan * p.cost) as QuantitySum
from product as p join invoice as i on i.ProductId = p.ProductId Group by Grouping Sets (productName, invoiceid,custid)