I have two tables with the following columns (identical columns in both tables):
- FunctionName,
- FrequencyCount
I want to merge these two tables into a final table with columns:
- Function Name
- Base Frequency count
- Compared Frequency count
- Delta of Frequency count
Merge operation should happen as follows:
If [FunctionName] is in Table1 and NOT in Table2,
[Base Frequency Count] = Table1.[FrequencyCount] [Compared Frequency Count] = 0 [Delta of Frequency Count] = Table1.[FrequencyCount]
If [FunctionName] is in Table2 and NOT in Table1,
[Base Frequency Count] = 0 [Compared Frequency Count] = Table2.[FrequencyCount] [Delta of Frequency Count] = Table2.[FrequencyCount]
If [FunctionName] is both in Table1 and Table2,
[Base Frequency Count] = Table1.[FrequencyCount] [Compared Frequency Count] = Table2.[FrequencyCount] [Delta of Frequency Count] = Table1.[FrequencyCount]-Table2.[FrequencyCount]
It is desirable that the query has good performance with minimum no. of joins. It would be great if someone can give good pointers.