我已经搜索过,无法找到完全符合我需求的解决方案。我有一个需要修改的mysql命令,但我被卡住了。以下代码按街道名称排序,但我也需要按#排序。这是我的代码:
SELECT * from property_details
ORDER BY SUBSTR(LTRIM(address), LOCATE(' ',LTRIM(address))) ASC
这样做:
320 Booken Pine
803 E. Cordy Ct.
2046 Last Fine Court
2000 Last Fine Court
2019 Last Fine Court
27-A Persons Alley
27-B Persons Alley
我需要这样做:
320 Booken Pine
803 E. Cordy Ct.
2000 Last Fine Court
2019 Last Fine Court
2046 Last Fine Court
27-A Persons Alley
27-B Persons Alley
任何帮助非常感谢。非常感谢你的进步。
答案 0 :(得分:0)
您需要第二个ORDER BY
条件来按行号对具有相同街道名称的行进行排序。
SELECT * from property_details
ORDER BY SUBSTR(LTRIM(address), LOCATE(' ',LTRIM(address))) ASC,
LEFT(address, LOCATE(' ',LTRIM(address)) ASC