Mysql
 sql >> Database >  >> RDS >> Mysql

SQL:Ordina per colonna, quindi per sottostringa mescola asc e desc

Dimostrazione qui

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