Final answer:
To generate a report with the total sales by customer and by product, including subtotals and a grand total, use the SQL GROUP BY clause with the ROLLUP function in conjunction with the SUM function.
Step-by-step explanation:
To list the total sales by customer and by product, including subtotals by customer and a grand total for all product sales using SQL, you would typically make use of the SUM function along with GROUP BY and ROLLUP (or CUBE) functions for generating subtotals and grand totals. Your SQL might look similar to this:
SELECT CustomerID, ProductID, SUM(SaleAmount) AS TotalSales
FROM Sales
GROUP BY ROLLUP (CustomerID, ProductID);
This SQL statement assumes you have a Sales table with columns for CustomerID, ProductID, and SaleAmount. The ROLLUP generates the hierarchical subtotal and grand total rows.
Note that different SQL database systems might have specific syntax or functions for these operations, so you would need to adjust the query according to the SQL dialect you are using, such as T-SQL for Microsoft SQL Server or PL/SQL for Oracle.