Matherial路径树输出

时间:2016-10-18 12:37:12

标签: mysql sql tree

我的列有像

这样的matherial路径
b
b1
b11  
c    
c1   
d    
e    
f    
g   
g1 

我怎么能这样做desc输出(树顺序desc输出)?

g
g1
f
e
d
c
c1
b
b1
b11

1 个答案:

答案 0 :(得分:0)

您需要使用ascii函数

create table t(col varchar(10));
insert into t
select 'b' union all
select 'b1' union all
select 'b11' union all
select 'c' union all
select 'c1' union all   
select 'd' union all    
select 'e' union all    
select 'f' union all    
select 'g' union all   
select 'g1';

select * from t 
order by 
ascii(col) desc, 
length(col) ;

结果是

col
g
g1
f
e
d
c
c1
b
b1
b11

SQLFiddle链接http://sqlfiddle.com/#!9/eaf954/4