简体   繁体   中英

Trying to create a loop in SQL to count every time the agent Id shows up in different month it would count one more than the previous month

I'm trying to create a count where every time Agent Id shows up it would count one more than the previous month.

Image of end state:

结束状态的图像

You seem to be looking for row_number() :

select t.*, row_number() over(partition by name order by d_month desc) cnt
from mytable t

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM