Untitled

yoyoy
 avatar
user_0223141589
mysql
a year ago
691 B
6
Indexable
Never
SELECT
  sm.REFERENCE,
  sm.WRITE_DATE,
  pt.DEFAULT_CODE part_num,
  pt.NAME part_name,
  sm.PRODUCT_QTY,
  sl1.NAME from_loc,
  sl2.NAME to_loc
FROM
  BIZ.DBT_STG.STG_ODOO_PROD__STOCK_MOVE sm
  JOIN BIZ.DBT_STG.STG_ODOO_PROD__PRODUCT_PRODUCT pp ON pp.id = sm.PRODUCT_ID
  JOIN BIZ.DBT_STG.STG_ODOO_PROD__PRODUCT_TEMPLATE pt ON pt.id = pp.PRODUCT_TMPL_ID
  JOIN BIZ.DBT_STG.STG_ODOO_PROD__STOCK_LOCATION sl1 on sm.LOCATION_ID = sl1.ID
  JOIN BIZ.DBT_STG.STG_ODOO_PROD__STOCK_LOCATION sl2 on sm.LOCATION_DEST_ID = sl2.ID
WHERE
  pt.CATEG_ID in (1,9)
  and sm.STATE = 'done'
  and (sl1.usage in ('supplier','production','inventory') or sl2.usage in ('production','inventory'))
ORDER BY 2 DESC