1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| WITH Personne (Nom, Naiss) AS
(
SELECT 'AA', convert(smalldatetime, '01/01/2005', 103) union ALL
SELECT 'BB', convert(smalldatetime, '15/04/2005', 103) union ALL
SELECT 'CC', convert(smalldatetime, '05/08/2006', 103) union ALL
SELECT 'DD', convert(smalldatetime, '09/10/2006', 103) union ALL
SELECT 'EE', convert(smalldatetime, '25/09/2007', 103) union ALL
SELECT 'FF', convert(smalldatetime, '04/12/2009', 103)
)
, Temp (Nom, Naiss, rn) AS
(
select Nom, Naiss, row_number() over(order by Naiss desc)
from Personne
where Naiss < convert(smalldatetime, '10/12/2006', 103)
)
select Nom, Naiss
from Temp
where rn = 1;
Nom Naiss
---- -----------------------
DD 2006-10-09 00:00:00 |
Partager