按数字排序,其中可以是连字符 - mysql
order by numbers where can be hyphens - mysql
我有一个查询说
select * from table order by numbers asc
号码是:32,-,11,76,-
我得到的是 -,-,11,32,76
(开头是连字符)
我要在查询中更改什么才能在末尾添加连字符?
您将数字存储为 varchar(),当您拥有 1,11,9,5...
等数据时会遇到更多麻烦,并且排序将具有 1,11,5,9...
这是您可以管理它的方法
select * from table_name
order by case when numbers ='-' then 2 else 1 end,numbers+0 ;
首先,我尝试使用带有类型转换的条件流进行排序
SELECT * FROM `table` ORDER BY numbers = '-', numbers+0 asc
如果要反向否定条件流
SELECT * FROM `table` ORDER BY numbers != '-', numbers+0 asc
我有一个查询说
select * from table order by numbers asc
号码是:32,-,11,76,-
我得到的是 -,-,11,32,76
(开头是连字符)
我要在查询中更改什么才能在末尾添加连字符?
您将数字存储为 varchar(),当您拥有 1,11,9,5...
等数据时会遇到更多麻烦,并且排序将具有 1,11,5,9...
这是您可以管理它的方法
select * from table_name
order by case when numbers ='-' then 2 else 1 end,numbers+0 ;
首先,我尝试使用带有类型转换的条件流进行排序
SELECT * FROM `table` ORDER BY numbers = '-', numbers+0 asc
如果要反向否定条件流
SELECT * FROM `table` ORDER BY numbers != '-', numbers+0 asc