按门牌号的 SQL 订单地址 [英] SQL order address by house number

查看:39
本文介绍了按门牌号的 SQL 订单地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以如果我有结果

11 The street
9 The street 
59 The street

一个普通的 ORDER BY ASC 做到这一点

A regular ORDER BY ASC does this

11 The street
59 The street 
9 The street

我如何通过 ASC 订购并让数字像这样计数

How can I order by ASC and have the numbers count up like

9 The street
11 The street 
59 The street

推荐答案

请尝试:

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

SQL 小提琴演示

对于MySql,请尝试:

For MySql, please try:

select *
From tbl
order by convert(SUBSTRING_INDEX(Col, ' ', 1), UNSIGNED INTEGER)

MySql Fiddle

这篇关于按门牌号的 SQL 订单地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆