I use MS-SQL and have the following two tables, where I want to extract the values to create the third table within one SQL query.
The answer from here helped me, but it's not enough.
sql sum data from multiple tables
Also it is important for me, that when there is no deregistration or no registration but a deregistration (fautly) I have to get the value 0 for that, so I need to have also results without a hit in both tables, but only in one.
Is it possible to get this result within one SQL query?
REG
[ATE] [Article] [Description] [Registered]
------------------------------------------
[1111] [MS1234] [SCREW] [500]
[2222] [MS1234] [SCREW] [600]
[2222] [AB9999] [BOLT] [100]
[3333] [XYZ123] [PAINT] [900]
[4444] [LMU232] [TOOL] [120]
DEREG
[ATE] [Article] [Description] [Deregistered]
------------------------------------------
[1111] [MS1234] [SCREW] [260]
[3333] [XYZ123] [PAINT] [900]
[4444] [LMU232] [TOOL] [20]
[9999] [TUM933] [SHIM] [5000]
RES
[ATE] [Article] [Description] [Registered] [Deregistered] [Rest]
--------------------------------------------------------------------------
[1111] [MS1234] [SCREW] [500] [260] [240]
[2222] [MS1234] [SCREW] [600] [0] [600]
[2222] [AB9999] [BOLT] [100] [0] [100]
[3333] [XYZ123] [PAINT] [900] [900] [0]
[4444] [LMU232] [TOOL] [120] [20] [100]
[9999] [TUM933] [SHIM] [0] [5000] [-5000]