I have got the set of data as follow
name date
x 2014-01-01
x 2014-01-02
y 2014-01-03
x 2014-01-04
and I'm trying to get this result
name date row_num
x 2014-01-01 1
x 2014-01-02 2
y 2014-01-03 1
x 2014-01-04 1
I have tried to run this query
select name,
date,
row_number () over (partition by name order by date) as row_num
from myTBL
but unfortunately I get this result
name date row_num
x 2014-01-01 1
x 2014-01-02 2
y 2014-01-03 1
x 2014-01-04 3
Please help.
partition by
statement says that partitions are based solely onname
. The result you got is the result you asked for. The result you seem to want is that partitions reset every time a run ofname
changes. I don't think you can do this with a simple window function. You'll need one or two levels of subquery. – Siqueiros