Skip to content

Instantly share code, notes, and snippets.

@cavebatsofware
Created December 5, 2013 18:33
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 cavebatsofware/7810736 to your computer and use it in GitHub Desktop.
Save cavebatsofware/7810736 to your computer and use it in GitHub Desktop.
Missing product
select
o.order_id as 'NEG order',
d.client_reference as 'Order number',
o.status as 'Order status',
p.name as 'Product name',
p.sku as 'SKU',
p.upc as 'Barcode',
SUM(i.quantity) as 'Order calls for',
SUM(IFNULL(y.available, 0)) as 'Available',
SUM(IFNULL(y.allocated, 0)) as 'Allocated to other orders',
SUM(IFNULL(y.quantity, 0)) as 'Overall Quantity',
d.order_date
from
orders o
inner join
order_details d ON o.order_id = d.order_id
inner join
order_inventory i ON o.order_id = i.order_id
inner join
nep_products p ON i.product_id = p.id
left outer join
inventory y ON y.product_id = i.product_id
where
o.client_id = 'CLIENT_ID'
and status = 'Saved'
group by o.order_id , p.sku
order by o.order_id , p.sku
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment