开发者

Oracle, Inserting correlative numbers based on other fields

Sorry for my english:

My q开发者_如何转开发uery select date from mytable returns something like this:

DATE

27/09/2011
27/09/2011
27/09/2011
27/09/2011
28/09/2011
28/09/2011
29/09/2011
29/09/2011
29/09/2011

I also need that my query returns a correlative based on each diferent date. something like...

DATE         | CORRELATIVE
             |
27/09/2011   | 1
27/09/2011   | 2
27/09/2011   | 3
27/09/2011   | 4
28/09/2011   | 1
28/09/2011   | 2
29/09/2011   | 1
29/09/2011   | 2
29/09/2011   | 3

I need help to get it, something like select date, any_way_to_get_it from mytable thk!


Here's the function you should use.

SELECT date, ROW_NUMBER()
   OVER (PARTITION BY date ORDER BY date) AS any_way_to_get_it 
   FROM mytable;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜