MySQL CAST和ASC/DESC [英] mySQL CAST and ASC / DESC
本文介绍了MySQL CAST和ASC/DESC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个mysql_query
I have a mysql_query
SELECT * FROM table ORDER BY CAST(row AS DECIMAL)
,并想要更改排序方向. 我尝试了 ASC 和 DESC ,但是它们返回的排序方向完全相同.
and want to change the sort direction. I tried ASC and DESC but both return exactly the same sort direction.
我该如何求助?
谢谢,问候
朱利安
推荐答案
如果您的row
列中仅包含一个_
字符,且字母前的部分和数字后的部分将起作用:
If your row
column has only one _
character inside, with the part before being alphabetic and the part after being numeric, this will work:
SELECT
*
, SUBSTRING_INDEX(row, '_', 1) AS FirstPart
, CAST(SUBSTRING_INDEX(row, '_', -1) AS UNSIGNED) AS SecondPart
FROM
TableX
ORDER BY
FirstPart
, SecondPart
这篇关于MySQL CAST和ASC/DESC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文