oracle order by在同一列可以某些值升序 某些值降序吗
3个回答
展开全部
这个是不行的,但是你可以用case when 语句把你要排序的值转换下,例如:
--t表里的值是'a','b','c','d',我要它按照'd','b','c','a'排序
select t.*,
case
when t.id = 'd' then
1
when t.id = 'b' then
2
when t.id = 'c' then
3
else
4
end rn
from (select 'a' as id
from dual
union all
select 'b' as id
from dual
union all
select 'c' as id
from dual
union all
select 'd' as id from dual) t
order by case
when t.id = 'd' then
1
when t.id = 'b' then
2
when t.id = 'c' then
3
else
4
end
--t表里的值是'a','b','c','d',我要它按照'd','b','c','a'排序
select t.*,
case
when t.id = 'd' then
1
when t.id = 'b' then
2
when t.id = 'c' then
3
else
4
end rn
from (select 'a' as id
from dual
union all
select 'b' as id
from dual
union all
select 'c' as id
from dual
union all
select 'd' as id from dual) t
order by case
when t.id = 'd' then
1
when t.id = 'b' then
2
when t.id = 'c' then
3
else
4
end
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询