Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- WITH dsra AS (
- SELECT
- --dsra.restaurant_id,
- --dsra.restaurant_name,
- --dsra.orders_total_sum
- *
- FROM public_test.dm_settlement_report_actual dsra
- ),
- dsre AS (
- SELECT
- --dsre.restaurant_id,
- --dsre.restaurant_name,
- --dsre.orders_total_sum
- *
- FROM public_test.dm_settlement_report_expected dsre
- ),
- DIFFS AS (
- SELECT
- COALESCE(dsra.restaurant_id, dsre.restaurant_id) AS restaurant_id,
- COALESCE(dsra.restaurant_name, dsre.restaurant_name) AS restaurant_name,
- dsra.orders_count as orders_count_act,
- dsre.orders_count as orders_count_exp,
- COALESCE(dsra.orders_count, 0) - COALESCE(dsre.orders_count, 0) AS orders_count_diff,
- dsra.orders_total_sum AS orders_total_sum_act,
- dsre.orders_total_sum AS orders_total_sum_exp,
- COALESCE(dsra.orders_total_sum, 0) - COALESCE(dsre.orders_total_sum, 0) AS orders_total_sum_diff,
- dsra.orders_bonus_payment_sum AS orders_bonus_payment_sum_act,
- dsre.orders_bonus_payment_sum AS orders_bonus_payment_sum_exp,
- COALESCE(dsra.orders_bonus_payment_sum, 0) - COALESCE(dsre.orders_bonus_payment_sum, 0) AS orders_bonus_payment_sum_diff,
- dsra.orders_bonus_granted_sum AS orders_bonus_granted_sum_act,
- dsre.orders_bonus_granted_sum AS orders_bonus_granted_sum_exp,
- COALESCE(dsra.orders_bonus_granted_sum, 0) - COALESCE(dsre.orders_bonus_granted_sum, 0) AS orders_bonus_granted_sum_diff,
- dsra.order_processing_fee AS order_processing_fee_act,
- dsre.order_processing_fee AS order_processing_fee_exp,
- COALESCE(dsra.order_processing_fee, 0) - COALESCE(dsre.order_processing_fee, 0) AS order_processing_fee_diff,
- dsra.restaurant_reward_sum AS restaurant_reward_sum_act,
- dsre.restaurant_reward_sum AS restaurant_reward_sum_exp,
- COALESCE(dsra.restaurant_reward_sum, 0) - COALESCE(dsre.restaurant_reward_sum, 0) AS restaurant_reward_sum_diff
- FROM dsra
- FULL JOIN dsre ON dsra.restaurant_name = dsre.restaurant_name
- )
- SELECT
- *
- FROM DIFFS
- where orders_count_diff <> 0 or
- orders_total_sum_diff <> 0 or
- orders_bonus_payment_sum_diff <> 0 or
- orders_bonus_granted_sum_diff <> 0 or
- order_processing_fee_diff <> 0 or
- restaurant_reward_sum_diff <> 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement