Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. SELECT
  2. orders.id,
  3. cost_total AS stored_cost_total,
  4. IFNULL(SUM(IF(use_effective = TRUE, effective_value, estimated_main_value + estimated_shelf_value)), 0) AS calcd_cost_total
  5. FROM
  6. orders
  7. LEFT JOIN
  8. order_costs ON orders.id = order_id
  9. AND order_costs.deleted_at IS NULL
  10. GROUP BY order_id
  11. HAVING
  12. (cost_total <> IFNULL(SUM(IF(use_effective = TRUE, effective_value, estimated_main_value + estimated_shelf_value)), 0)
  13. OR cost_total IS NULL AND IFNULL(SUM(IF(use_effective = TRUE, effective_value, estimated_main_value + estimated_shelf_value)), 0) IS NOT NULL
  14. 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