Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- insert into cdm.dm_settlement_report (restaurant_id, restaurant_name, settlement_date, orders_count, orders_total_sum, orders_bonus_payment_sum, orders_bonus_granted_sum, order_processing_fee, restaurant_reward_sum)
- select
- r.restaurant_id
- ,r.restaurant_name
- ,t."date"
- ,fps.count
- ,fps.total_sum
- ,fps.bonus_payment
- ,fps.bonus_grant
- ,fps.total_sum*0.25 as order_processing_fee
- ,fps.total_sum - (fps.total_sum*0.25) - bonus_payment as restaurant_reward_sum
- from dds.fct_product_sales fps
- left join dds.dm_orders o on fps.order_id = o.id
- left join dds.dm_restaurants r on o.restaurant_id = r.id
- left join dds.dm_timestamps t on o.timestamp_id = t.id
- where o.order_status = 'CLOSED'
- ON CONFLICT (restaurant_id, settlement_date) DO UPDATE
- SET --restaurant_name = EXCLUDED.restaurant_name,
- orders_count = EXCLUDED.orders_count,
- orders_total_sum = EXCLUDED.orders_total_sum,
- orders_bonus_payment_sum = EXCLUDED.orders_bonus_payment_sum,
- orders_bonus_granted_sum = EXCLUDED.orders_bonus_granted_sum;
- --order_processing_fee = EXCLUDED.order_processing_fee,
- --restaurant_reward_sum = EXCLUDED.restaurant_reward_sum;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement