原文链接:https://www.cnblogs.com/kevin-kw/p/6256585.html
如下有一个城市区域表region:
我们需要对上表region按city分组,对region进行排序,得到如下结果:
select city,region, right('100'+row_number()over(partition by city order by region),2) as region_no from region
本版本补充,这样可以将01变为1:
select city,region, CAST(right('100'+row_number()over(partition by city order by region),2),AS INT) as region_no from region