Here's that query. Note that multiple records will be returned for a single order if multiple tax-rates are present.
Code:
SELECT DISTINCT o.orders_id, o.date_purchased, o.payment_method, o.customers_name, ot_tax.`title`, op.products_tax, ot_sub.`value`, ot_tax.`value`, ot_total.`value`
FROM orders AS o
LEFT JOIN orders_products AS op
ON op.orders_id = o.orders_id
LEFT JOIN orders_total AS ot_tax
ON ot_tax.orders_id = o.orders_id
AND ot_tax.`class` = 'ot_tax'
LEFT JOIN orders_total AS ot_sub
ON ot_sub.orders_id = o.orders_id
AND ot_sub.`class` = 'ot_subtotal'
LEFT JOIN orders_total AS ot_total
ON ot_total.orders_id = o.orders_id
AND ot_total.`class` = 'ot_total'
WHERE o.date_purchased BETWEEN '2019-01-01' AND '2019-12-31'
ORDER BY o.date_purchased ASC;
Bookmarks