Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT
- orders.id,
- cost_total AS stored_cost_total,
- IFNULL(SUM(IF(use_effective = TRUE, effective_value, estimated_main_value + estimated_shelf_value)), 0) AS calcd_cost_total
- FROM
- orders
- LEFT JOIN
- order_costs ON orders.id = order_id
- AND order_costs.deleted_at IS NULL
- GROUP BY order_id
- HAVING
- (cost_total <> IFNULL(SUM(IF(use_effective = TRUE, effective_value, estimated_main_value + estimated_shelf_value)), 0)
- OR cost_total IS NULL AND IFNULL(SUM(IF(use_effective = TRUE, effective_value, estimated_main_value + estimated_shelf_value)), 0) IS NOT NULL
- OR cost_total IS NOT NULL AND IFNULL(SUM(IF(use_effective = TRUE, effective_value, estimated_main_value + estimated_shelf_value)), 0) IS NULL);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement