1 2 3 4 5 6 7 8 9 10 11 12 13
| WITH OrderByTest (Departement, CorpsEmploi, ClasseEmploi, SalaireQuotidien, RowNum, CountOrders) AS
(
SELECT Departement, CorpsEmploi, ClasseEmploi,
SalaireQuotidien,
ROW_NUMBER() OVER (PARTITION BY Departement, CorpsEmploi, ClasseEmploi ORDER BY SalaireQuotidien) AS RowNum,
COUNT(Accréditation) OVER (PARTITION BY Departement,CorpsEmploi, ClasseEmploi) AS CountOrders
FROM #temp01 AS Test
)
SELECT Departement, CorpsEmploi, ClasseEmploi, AVG(SalaireQuotidien) as 'Médiane', CountOrders AS 'Nombre'
FROM OrderByAccreditation
WHERE RowNum BETWEEN (CountOrders + 1)/2 AND (CountOrders + 2)/2
GROUP BY Departement, CorpsEmploi, ClasseEmploi, CountOrders |
Partager