sql实现分组中并进行序号排序

sql:row_number() over(partition by xxxxxxxxxx order by yyyyyyyyyyyyy)

xxxxxxxxxx:分组字段;yyyyyyyyyyyyy:排序字段

select  
row_number() over(partition by d.area_code order by a.customer_name),  
a.customer_name, d.area_code 

from jc_customer as a
left join jc_province as b on a.province = b.province_name
left join jc_city as c on a.city = c.city_name and b.province_code = c.province_code
left join jc_area as d on a.area = d.area_name and c.city_code = d.city_code
order by d.area_code 

 

 

sql实现分组中并进行序号排序_第1张图片

你可能感兴趣的:(sql)