我有一个MySQL表|源|目的地|距离。邮政编码可以像这样在源列或目标列中。当我尝试按顺序输出时,输出就像下面显示的那样,而不是最后一行。我该如何解决这个问题。
DV116 | DH5ADZZ | 7.0
Select
healthcare.address_matrix.*
From
healthcare.address_matrix
Where
(healthcare.address_matrix.source_postcode = 'Dv116BL') Or
(healthcare.address_matrix.dest_postcode = 'Dv116BL')
Order By
healthcare.address_matrix.distance
答案 0 :(得分:0)
如果没有按字段顺序提取订单,订单将是随机的。 我认为如果您明确命名并重命名您选择和订购的字段,将会有所帮助。不要使用* construct。
答案 1 :(得分:0)
由于距离是一个varchar,你应该尝试按顺序进行排序:
Order By CAST(`healthcare.address_matrix.distance` AS SIGNED) DESC
答案 2 :(得分:0)
将列转换为decimal
Select healthcare.address_matrix.* From healthcare.address_matrix Where (healthcare.address_matrix.source_postcode = 'Dv116BL') Or (healthcare.address_matrix.dest_postcode = 'Dv116BL') Order By CAST(healthcare.address_matrix.distance AS DECIMAL(5,2)) DESC