1

I am trying to (within a query) assign a row number to a date grouped by a customer ID. I realise that that makes little or no sense as a description so I have included an examples below (I don't have the reputation to post images yet and HTML tables dont seem to work here so I have included an HTML table which can be run on a browser. Apologies for the inconvenience):

Cust_ID Date        Assigned_value
-----------------------------------
1       11/12/2014  1
1       12/12/2014  2
1       13/12/2014  3
1       14/12/2014  4
1       15/12/2014  5
2       16/12/2014  1
2       17/12/2014  2
2       18/12/2014  3
3       11/12/2014  1
3       12/12/2014  2
3       13/12/2014  3

Any help would be much appreciated

mjsqu
  • 5,151
  • 1
  • 17
  • 21
Nic2352
  • 95
  • 8

1 Answers1

2

I think you are looking for the row_number() functions:

select cust_id, date,
       row_number() over (partition by cust_id order by date) as assigned_value
from table t;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786