Looking for help with a query to get the sum of the subtotals for each price category from a list of line items, by order. Scratching my head on the group by stuff.
There are 3 categories: setup, build, and finishing. I'd like to get a total for each category per order. Testing shows my sql foo is rusty and looking for guidance on how to roll this stuff up. I'm already querying a view to make this simpler.
http://sqlfiddle.com/#!9/acb02/3
CREATE TABLE `OrderLineItems` (
`orderId` INT(11) NOT NULL,
`dt` DATETIME,
`buyerEmail` VARCHAR(512),
`orgId` INT(11) NOT NULL,
`description` VARCHAR(512),
`application` VARCHAR(512),
`category` VARCHAR(30),
`quantity` INT(5),
`price` DECIMAL(9,2),
`subtotal` DECIMAL(19,2)
)
Looking for one row per order in the result, with the total for each price category. A total cost for the order would be bonus.
Order Id | Setup Total | Build Total | Finishing Total | All Total
--------------------------------------------------------------------
Also, adding in the date, is it possible to get a grouping by month for the 3 categories?
Month | Setup Tot | Build Tot | Finishing Tot | All Tot
---------------------------------------------------------
1/16 |
2/16 |