Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 按门牌号列出的SQL订单地址_Mysql_Sql - Fatal编程技术网

Mysql 按门牌号列出的SQL订单地址

Mysql 按门牌号列出的SQL订单地址,mysql,sql,Mysql,Sql,所以如果我有结果 11 The street 9 The street 59 The street ASC的常规订单可以做到这一点 11 The street 59 The street 9 The street 我怎样才能按ASC下单,并让数字像这样计数 9 The street 11 The street 59 The street 请尝试: select * From tbl order by cast(Left(Col, PatIndex('%[^0-9]%', Col))

所以如果我有结果

11 The street
9 The street 
59 The street
ASC的常规
订单可以做到这一点

11 The street
59 The street 
9 The street
我怎样才能按ASC下单,并让数字像这样计数

9 The street
11 The street 
59 The street
请尝试:

select *
From tbl
order by cast(Left(Col, PatIndex('%[^0-9]%', Col)) as int)
select *
From tbl
order by convert(SUBSTRING_INDEX(Col, ' ', 1), UNSIGNED INTEGER)

对于MySql,请尝试:

select *
From tbl
order by cast(Left(Col, PatIndex('%[^0-9]%', Col)) as int)
select *
From tbl
order by convert(SUBSTRING_INDEX(Col, ' ', 1), UNSIGNED INTEGER)
另一种解决方案(有点简单);只需查看示例数据,并假设所有数据字符串中都有公共的街道。否则,TechDo建议的应该是我会选择的(通用解决方案)


你使用什么数据库引擎?请显示给你这些结果+1的整个查询。不过,我想他会想先按地址再按数字排序。建议编辑:
从tbl中按子字符串(Col,PatIndex('%[^0-9]',Col),999)选择*,cast(Left(Col,PatIndex('%[^0-9]',Col))作为int)
是的,这将使更多sense@TechDo谢谢,我现在很难区分街道的名称,按街道名称再按编号排序,子字符串_INDEX函数似乎无法从左起点向右移动。请参阅@user1209203,也许您应该将其作为问题的编辑发布?你没提到需要这么做。