I have two tables.
Table 1 : 'DQ' is the golden source of information Table 2 : 'PS' is whats currently in the DB.
What I would like to do is compare AMOUNT from the 'DQ' table vs VALIDATED in the 'PS' Table
As you can see although the column names between two tables are different there is a match:
dq.Account_Number = PS.Account_Code__C dq.AMOUNT = PS.VALIDATED
Please note that I may have Account_Number / Account_Code__C in one table and not the other.
--//AUM 1M SELECT Account_Number, sum(AMOUNT) FROM DQ where Account_Number = '1234' group by Account_Number
--//validated 1M SELECT Account_Code__C, sum(VALIDATED) FROM PS where Account_Code__C = '1234' group by Account_Code__C
Other possible scenarios:
I have written the following query:
SELECT DISTINCT b.Account_Code__C, Amount, Validated FROM ( SELECT DISTINCT Account_Number, sum(AMOUNT) as Amount FROM DQ WHERE 1=1 group by Account_Number --// AND Account_Number=@Account_Code )a FULL JOIN ( SELECT DISTINCT Account_Code__C, sum(VALIDATED) as FROM PS WHERE 1=1 group by Account_Code__C --// AND Account_Code__C=@Account_Code )b ON a.Account_Number=b.Account_Code__C WHERE 1=1 and Account_Code__C = '1234'
I would like someone to validate if possible.