Hopefully someone can point me in the right direction here.
See below query.
SELECT day_id,month_id,time_id,
row_number() over (partition BY month_id order by day_id ) rn
FROM minute_bars_fact order by month_id, day_Id, time_id
Produces output:
DAY_ID MONTH_ID Time_id rn
02-JAN-11 JAN-2011 1080 1
02-JAN-11 JAN-2011 1081 2
02-JAN-11 JAN-2011 1082 3
02-JAN-11 JAN-2011 1083 4
02-JAN-11 JAN-2011 1084 5
02-JAN-11 JAN-2011 1085 6
02-JAN-11 JAN-2011 1086 7
02-JAN-11 JAN-2011 1087 8
My expectation here would be that rn would only be incrementing on each new day. Obviously that isn’t the case. Am i doing something wrong here?
Edit:
Day is not always the same.
02-JAN-11 JAN-2011 1436 357
02-JAN-11 JAN-2011 1437 358
02-JAN-11 JAN-2011 1438 359
02-JAN-11 JAN-2011 1439 360
03-JAN-11 JAN-2011 0 361
03-JAN-11 JAN-2011 1 362
03-JAN-11 JAN-2011 2 363
03-JAN-11 JAN-2011 3 364
No this is incorrect. You would need to use
RANKorDENSE_RANKto achieve this behaviour. NotROW_NUMBER