CREATE TABLE TRAFFIC_CELLULES(identificateur_de_cellule CHAR(3),traffic INT,date DATETIME); <br />
<br />
INSERT INTO TRAFFIC_CELLULES(identificateur_de_cellule,traffic,date) VALUES ('A',100,'01/01/2008') <br />
INSERT INTO TRAFFIC_CELLULES(identificateur_de_cellule,traffic,date) VALUES ('A',200,'01/01/2008') <br />
INSERT INTO TRAFFIC_CELLULES(identificateur_de_cellule,traffic,date) VALUES ('A',225,'01/01/2008') <br />
INSERT INTO TRAFFIC_CELLULES(identificateur_de_cellule,traffic,date) VALUES ('A',400,'01/01/2008') <br />
INSERT INTO TRAFFIC_CELLULES(identificateur_de_cellule,traffic,date) VALUES ('A',150,'01/02/2008') <br />
INSERT INTO TRAFFIC_CELLULES(identificateur_de_cellule,traffic,date) VALUES ('A',175,'01/02/2008') <br />
INSERT INTO TRAFFIC_CELLULES(identificateur_de_cellule,traffic,date) VALUES ('A',200,'01/02/2008') <br />
INSERT INTO TRAFFIC_CELLULES(identificateur_de_cellule,traffic,date) VALUES ('B',100,'01/01/2008') <br />
INSERT INTO TRAFFIC_CELLULES(identificateur_de_cellule,traffic,date) VALUES ('B',100,'01/03/2008') <br />
<br />
WITH selection <br />
AS <br />
( <br />
SELECT identificateur_de_cellule,traffic,datepart(ww,date) as sem,ROW_NUMBER() OVER (PARTITION BY identificateur_de_cellule,datepart(ww,date) ORDER BY traffic) as OrderRank FROM TRAFFIC_CELLULES <br />
) <br />
SELECT * FROM selection where OrderRank <= 3 <br />
<br />
Resultat: <br />
<br />
A 100 1 1 <br />
A 200 1 2 <br />
A 225 1 3 <br />
A 150 5 1 <br />
A 175 5 2 <br />
A 200 5 3 <br />
B 100 1 1 <br />
B 100 9 1