【问题标题】:Matherial path tree-output数学路径树输出
【发布时间】:2016-10-18 12:37:11
【问题描述】:

我有一列带有数学路径的列,例如

b
b1
b11  
c    
c1   
d    
e    
f    
g   
g1 

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

g
g1
f
e
d
c
c1
b
b1
b11

【问题讨论】:

    标签: mysql sql tree


    【解决方案1】:

    你需要使用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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-19
      • 2013-02-26
      • 1970-01-01
      • 1970-01-01
      • 2023-03-13
      • 1970-01-01
      • 2021-08-06
      • 1970-01-01
      相关资源
      最近更新 更多