I have a table that lists service calls for employees. i have a view set up to view the sum of the invoices in the table.
Select EmployeeID, SUM(InvoiceAmount) as "Total $ Amount Of Calls For January"
From Calls
WHERE Date BETWEEN '2013/01/01' AND '2013/01/31'
Group by EmployeeID
this works great but i have to do it twelve times to view each month and this seems a bit redundant. i would like to be able to use a sub query to display EmployeeID and then list each month with totals underneath.
EmployeeID JAN FEB MAR APR ...
john 444 555 342 654
jim 945 675 232 465
ive tried a bunch of things and cant get even close…i need something like this, but that works…
SELECT
EmployeeID,
(SELECT SUM(InvoiceAmount) FROM Orders WHERE DATE BETWEEN '2013/01/01' AND '2013/01/31') AS JAN,
(SELECT SUM(InvoiceAmount) FROM Orders WHERE DATE BETWEEN '2013/02/01' AND '2013/02/28') AS FEB,
(SELECT SUM(InvoiceAmount) FROM Orders WHERE DATE BETWEEN '2013/03/01' AND '2013/03/31') AS MAR,
FROM Calls
You can do something like this:
This works well if you’re looking at a particular year.
See it in action