sql >> Base de Datos >  >> RDS >> Mysql

SQL:ordene por columna, luego por subcadena, mezcle asc y desc

Demostración aquí

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