Advertisement
zotov-vs

dwh_refunds_products

Jun 1st, 2017
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. CREATE OR REPLACE ALGORITHM = MERGE VIEW dwh_refunds_products AS
  2.  
  3. SELECT
  4. rp.refunds_products_id
  5. , rp.refunds_id
  6. , rp.orders_products_id
  7. , IF(rp.is_defect = 'Y', 1, 0) AS is_defect
  8. , rp.defects_binds_id
  9. , CAST(IFNULL(rp.products_price,0) + IFNULL(rp.products_price_cash,0) + IFNULL(rp.products_price_card,0) AS DECIMAL(15,2)) AS products_price
  10. FROM refunds_products AS rp
  11. JOIN refunds AS r ON r.refunds_id = rp.refunds_id
  12. JOIN dwh_upload_config AS duc on duc.component = 'dwh_refunds_products'
  13. WHERE
  14. r.refunds_type_id = 1
  15. AND (duc.date_from_use = 0 OR r.date_added >= duc.date_from OR r.date_accepted >= duc.date_from)
  16. AND (duc.date_to_use = 0 OR r.date_added <= duc.date_to OR r.date_accepted <= duc.date_to)
  17. AND (duc.id_from_use = 0 OR rp.refunds_products_id >= duc.id_from)
  18. AND (duc.id_to_use = 0 OR rp.refunds_products_id <= duc.id_to)
  19. ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement