Skip to content

Instantly share code, notes, and snippets.

@JosephLeedy
Created April 23, 2025 15:43
Show Gist options
  • Save JosephLeedy/a447377f3f198875ad28461666139147 to your computer and use it in GitHub Desktop.
Save JosephLeedy/a447377f3f198875ad28461666139147 to your computer and use it in GitHub Desktop.
Generate a report of Custom Fees charged by order date
SELECT
DATE(so.created_at) AS 'Order Date',
fee.title AS 'Fee',
SUM(fee.base_value) AS 'Base Total Amount',
SUM(fee.value) AS 'Total Amount'
FROM custom_order_fees AS cof
JOIN JSON_TABLE(
cof.custom_fees,
'$' COLUMNS (
NESTED PATH '$.*' COLUMNS (
title VARCHAR(255) PATH '$.title',
value DECIMAL(10, 4) PATH '$.value',
base_value DECIMAL(10, 4) PATH '$.base_value'
)
)
) AS fee
LEFT JOIN sales_order AS so ON so.entity_id = cof.order_entity_id
GROUP BY DATE(so.created_at), fee.title;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment