Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE OR REPLACE ALGORITHM = MERGE VIEW dwh_refunds_products AS
- SELECT
- rp.refunds_products_id
- , rp.refunds_id
- , rp.orders_products_id
- , IF(rp.is_defect = 'Y', 1, 0) AS is_defect
- , rp.defects_binds_id
- , 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
- FROM refunds_products AS rp
- JOIN refunds AS r ON r.refunds_id = rp.refunds_id
- JOIN dwh_upload_config AS duc on duc.component = 'dwh_refunds_products'
- WHERE
- r.refunds_type_id = 1
- AND (duc.date_from_use = 0 OR r.date_added >= duc.date_from OR r.date_accepted >= duc.date_from)
- AND (duc.date_to_use = 0 OR r.date_added <= duc.date_to OR r.date_accepted <= duc.date_to)
- AND (duc.id_from_use = 0 OR rp.refunds_products_id >= duc.id_from)
- AND (duc.id_to_use = 0 OR rp.refunds_products_id <= duc.id_to)
- ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement