Reputation: 99
Description:
Need to find the sum of premium mismatch between two tables - if the sum of premium for particular category is not matched with Agent table then i want that to be capture
Desired result set
Sum of premium should be grouped by Category in this case sum of MTT is 219 in Demo but in Agent table sum of MTT is 221
So in this case my query should capture the mismatch and put the result as below (only for mismatch and if we do not have any mismatch then display 0)
Sum(premium) from Demo Minus Sum(premium) from Agent
Upvotes: 0
Views: 73
Reputation: 173046
consider below approach
select category, sum(premium) as diff
from (
select premium, category from Demo
union all
select -premium, category from Agent
)
group by category
Upvotes: 1