Search code examples
mysqlviewtranspose

How can I make an MySQL View for Tax per Order


My data:

Table How can I get there? I tried to make a MySQL view on my table TAX.

CREATE VIEW TaxSplitPerOrder AS SELECT OrderNumber, tax_invoiced, total_invoiced, created_at, tax_percent, SUM(tax_invoiced_order_item) FROM test GROUP by OrderNumber;


Solution

  • You need to include all of the other non-summarized columns from your SELECT in the GROUP BY clause. You may want to sum total_invoiced too or else you will still have 2 rows for each order number.