SHARE
TWEET

Untitled

a guest Oct 18th, 2019 113 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. SELECT products.id,
  2.        products.name,
  3.        product_categories.name,
  4.        products.product_type,
  5.        SUM(nin.qty) AS purchased,
  6.        SUM(nout.qty) AS sold
  7. FROM products
  8. LEFT OUTER JOIN product_categories ON (products.category_id = product_categories.id)
  9. LEFT OUTER JOIN nitems nin  ON (nin.product_id = products.id AND nin.iinvoice_id IS NOT NULL)
  10. LEFT OUTER JOIN nitems nout ON (nout.product_id = products.id AND nout.oinvoice_id IS NOT NULL)
  11. WHERE products.company = 2
  12. AND products.product_type = 'nonitemised'
  13. GROUP BY products.id, products.name, product_categories.name, products.product_type
  14. ORDER BY products.name;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top