I’m stuck on a SQL issue, I’m almost sure it’s all easy but I can’t find a proper answer. Below here is the example. I want to combine those 2 queries :
SELECT
num_rata, SUM(val_imp*0.01) AS amount
FROM table1
WHERE
col1 <> 0
AND num_contract = 88
GROUP BY num_rata
That returns something like :
1 215.00
2 220.00
3 210.00
4 115.00
5 315.00
And :
SELECT
num_rata, SUM(val_ban*0.01) AS amount
FROM table2
WHERE
num_contract = 2988
GROUP BY num_rata;
Example result set :
1 15.00
2 615.00
3 275.00
4 285.00
5 285.00
6 275.00
7 260.00
8 215.00
9 215.00
As a final result I would like something like this :
1 215.00 15.00
2 220.00 615.00
3 210.00 275.00
4 115.00 285.00
5 315.00 285.00
6 275.00
7 260.00
8 215.00
9 215.00
Thank you for any hint.
fabien.
You could use either a union or an outer join – I would prefer a union, like this: