Tuesday, February 23, 2010

Rank on a date

SELECT trunc(car_modification_date,'MM'),
       car_no,
       rank() over (partition by car_no,trunc(car_modification_date,'MM') ORDER BY car_modification_date desc) rank     
  FROM histo_carte hc
 WHERE car_no = 1280
--
is not the same as
--
SELECT trunc(car_modification_date,'MM'),
       car_no,
       rank() over (partition by car_no,trunc(car_modification_date,'MM') ORDER BY  trunc(car_modification_date,'MM') desc) rank      
  FROM histo_carte hc
 WHERE car_no = 1280
--
RANK = 1 as the date is always the same...so the rank remains also the same...

No comments:

Post a Comment