Skip to content

Instantly share code, notes, and snippets.

@mpchadwick
Last active November 5, 2015 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mpchadwick/bf1e26452a4bd36227bb to your computer and use it in GitHub Desktop.
Save mpchadwick/bf1e26452a4bd36227bb to your computer and use it in GitHub Desktop.
Orders Without Status History
# Get the number or orders without any status history
# Can be useful for debugging (e.g. it is expected that there is a status history such as "Authorize Amount"
SELECT
date(result.created_at),
count(result.entity_id) as Orders,
SUM(CASE WHEN result.comments IS NULL THEN 1 ELSE 0 END) as OrdersWithoutStatuses,
CONCAT(FLOOR(100 * SUM(CASE WHEN result.comments IS NULL THEN 1 ELSE 0 END) / count(result.entity_id)), '%') PercentageWithoutStatuses
FROM (
SELECT
sfo.entity_id as "entity_id",
sfo.increment_id as "order_id",
sfo.created_at as "created_at",
GROUP_CONCAT(sfosh.comment) as "comments"
FROM sales_flat_order sfo
LEFT JOIN sales_flat_order_status_history sfosh
ON sfo.entity_id = sfosh.parent_id
WHERE sfo.created_at > '2015-09-01'
GROUP BY sfo.entity_id
ORDER BY sfo.entity_id DESC
) result
GROUP BY date(result.created_at)
ORDER BY date(result.created_at) DESC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment