I’m new to SQL queries so hopes this question isn’t stupid.
I got two tables like this:
Table 1:
Name | Value | Count |
---|---|---|
global | g | 1 |
domain | x | 2 |
domain | y | 1 |
agg | ba | 1 |
Table 2:
Name | Value | Count |
---|---|---|
global | g | 1 |
domain | z | 1 |
agg | bb | 1 |
I need to get this kind of table – which is consist of all rows without duplications, and the global row should changed it’s count to the sum of the ‘domain’ rows from the first table only:
Table 3:
Name | Value | Count |
---|---|---|
global | g | 3 |
domain | x | 2 |
domain | y | 1 |
domain | z | 1 |
agg | ba | 1 |
agg | bb | 1 |
is this kind of operation is possible?
2
Answers
demo:db<>fiddle
global
rowglobal
row for the expected sum of the table1domain
records. Union it as well.Try this out
You can check on this db fiddle as well test case