Subject Looking for a special select-statement
Author

Hi,


we would need the below shown result-dataset from data shown in Tab1 and Tab2.

Can this be expressed with a select-statement?


Thank you for your help,

Josef Gschwendtner



Tab1

Key1   Value1

1          1000

2          2000

3          3000

4          4000

 

Tab2

Key2       Key1       Value2

1             1               400

2             1               400

3             2             2000

4             3             1000

5             3             1000

6             3               500

 

Result

Key1       Key2       Value

1             1               400

1             2               400

1             null            200

2             3             2000

3             4             1000

3             5             1000

3             6               500

3             null            500

4             null          4000


Note:

In Tab2 are 0 to n related records for each record in Tab1.

In return dataset should be one record with key2 is null if value1 <> sum(value2) for one relation.