Mysql
 sql >> Datenbank >  >> RDS >> Mysql

SQL:Sortieren Sie nach Spalte, dann nach Substring-Mischung aus Asc und Desc

Demo hier

select *
from #temp
order
by substring(id,1,2),
case
when substring(id,1,2)%2=0 then row_number() over (partition by substring(id,1,2) order by  SUBSTRING(id,4,3) desc)
else row_number() over (partition by substring(id,1,2) order by  SUBSTRING(id,4,3) asc)
end