SQL schema for creating custom reports

Okay, how about a Custom Report that breaks down my sales for 2015 (or any arbitrary period) by Customer? (When I say “sales” here, I mean “amounts invoiced to the customer,” preferably excluding Billable Expenses – but if it has to include Billable Expenses, then so be it.)

This would be terribly useful at this time of year, in order to reconcile income tax filings for payments reported by each client (Form 1099-MISC here in the U.S.) against company records of billings.

Something like this:

I can’t quite figure out the Manager flavour of the SQL to generate this table. Can you please help? (My SQL is weak, but I tried this and it doesn’t work for many reasons: SELECT SUM(TotalAmount) FROM SalesInvoices WHERE IssueDate BETWEEN '2015-01-01' AND '2015-12-31' GROUP BY CustomerName;)

To keep things simple, this request is just for a straightforward Custom Report of total invoiced amounts for the specified period broken down by customer. Ideally, though, since this is probably a very commonly needed report for any services-based company, it would be nice to have a formal Sales Report that includes this information and breaks it down by Income account. Something like this:

…and, if possible, an option to flip the hierarchy, with each customer listed underneath each Income account: