1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| with t1 (ID, incident, quantite1) as
(
select 23, 2345, 50 union all
select 24, 2345, 50 union all
select 32, 2456, 30 union all
select 26, 4356, 15
)
, t2 (ID, incident, Nom) as
(
select 45, 2345, 'A' union all
select 46, 2345, 'A' union all
select 57, 2456, 'A' union all
select 78, 4356, 'B'
)
, new_t1 (incident, quantite1) as
(
select distinct incident, quantite1
from t1
)
, new_t2 (incident, Nom) as
(
select distinct incident, Nom
from t2
)
select t2.Nom, sum(coalesce(t1.quantite1, 0)) as quantite
from new_t1 as t1
inner join new_t2 as t2
on t2.incident = t1.incident
group by t2.Nom;
Nom quantite
---- -----------
A 80
B 15 |
Partager