I have a table with information about the type of scrap generated on a bag making machine. Every time scrap in generated on either side of the machine (left or right, there are 2 packing machines on the one bag maker) a line is added to the table with the following information,
scrap_left, scrap_right, reason_left, reason_right
So if the left side found 2 bags that had dirt, a line might read like this,
| scrap_left | scrap_right | reason_left | reason_right | | 2 | | dirt | |
After a shift there are 20 - 30 lines with up to 20 different reason like so,
| scrap_left | scrap_right | reason_left | reason_right | | 2 | | dirt | | | | 4 | | torn | | | 1 | | line up | | | 2 | | torn | | 5 | | wide ties | |
I am generating a report in Excel using VB to perform the querys and its all working well.
But I want to generate a table with the totals like so
| Reason | Quantity | | Torn | 6 | | wide ties | 5 | | dirt | 2 | | line up | 1 |
Can I do this with a single query in MySQL or should I be doing it in VB?