树输出mysql

时间:2016-10-18 10:40:27

标签: mysql sql sorting

我有像

这样的专栏
1
11
12
2
21

我想按照

这样的desc顺序显示列
   2
   1
   11
   12
   13 

这意味着,我想按单个数字订购我的列 递减。 我怎么能这样做? DB - mysql

4 个答案:

答案 0 :(得分:2)

只需将值转换为字符串:

order by cast(col as varchar) desc

答案 1 :(得分:1)

试试这个:

select col from my_table order by (case when col = 2 then 0 else col end)

答案 2 :(得分:0)

  

这会帮助你......

SELECT c.column_name
FROM INFORMATION_SCHEMA.COLUMNS c
WHERE c.table_name = 'your-table_name'  
ORDER BY c.column_name DESC

答案 3 :(得分:0)

SELECT id
FROM
(
SELECT  id,2 as tag FROM test
WHERE id<10
UNION
SELECT id,1 as tag FROM test
WHERE id>=10
) as tmp
ORDER BY tag desc, CASE WHEN tag=2 then id ELSE id*(-1) END DESC