select x.INNER_RATE,row_number() over(order by CASE when x.inner_rate='AAA' then 0 END, CASE when x.inner_rate='AA' then 1 END, CASE when x.inner_rate='A' then 3 END, CASE when x.inner_rate='B' then 4 END, CASE when x.inner_rate='C' then 5 END, CASE when x.inner_rate='D' then 6 END, END desc,x.id) num from t_table x ;