【发布时间】: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
【问题讨论】:
我有一列带有数学路径的列,例如
b
b1
b11
c
c1
d
e
f
g
g1
我怎样才能做这样的 desc 输出(树顺序 desc 输出)?
g
g1
f
e
d
c
c1
b
b1
b11
【问题讨论】:
你需要使用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
【讨论】: