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
| with t1(t1id, t1ch) as
(select 1, 'truc' union all
select 2, 'bidule' union all
select 3, 'machin' union all
select 4, 'chose'
)
, t2 (t2id, t2ch, t1id) as
(select 1, 'A', 1 union all
select 2, 'B', 1 union all
select 3, 'G', 2 union all
select 4, 'Y', 4 union all
select 5, 'H', 2 union all
select 6, 'I', 2 union all
select 7, 'J', 2 union all
select 8, 'C', 1
)
select t1.t1id
, t1.t1ch
, count(t2.t2id)
from t1
left join t2
on t2.t1id=t1.t1id
where t1.t1id=2
group by t1.t1id
, t1.t1ch |
Partager