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 35 36 37 38 39 40
| with T1(C1, C2, C3) as
(select 1, 18, '2025-01-10' union all
select 1, 15, '2025-01-12' union all
select 1, 18, '2025-01-19' union all
select 1, 07, '2025-01-25' union all
select 1, 14, '2025-02-01' union all
select 1, 11, '2025-02-07' union all
select 1, 20, '2025-02-10' union all
select 2, 08, '2025-01-10' union all
select 2, 06, '2025-01-12' union all
select 2, 11, '2025-01-14' union all
select 2, 12, '2025-01-19' union all
select 2, 16, '2025-01-25' union all
select 2, 11, '2025-02-07' union all
select 2, 11, '2025-02-10' union all
select 3, 15, '2025-01-10' union all
select 3, 19, '2025-01-12' union all
select 3, 18, '2025-01-19'
)
, T2(C1, C2, C3) as
(select C1
, C2
, row_number()
over (partition by C1 order by C3 desc)
from T1
)
, T3(ID, NM, PR) as
(select 1, 'Martin', 'Sidonie' union all
select 2, 'Dupont', 'Jean' union all
select 3, 'Legros', 'Pascal'
)
select C1 as "Ident"
, T3.PR as "Prénom"
, T3.NM as "Nom"
, cast(avg(C2) as decimal (5,2)) as "Moyenne"
from T2
inner join T3
on T3.ID=T2.C1
where C3 < 6
group by C1, PR, NM |
Partager