Home >Backend Development >PHP Tutorial >mysql 排序解决方法

mysql 排序解决方法

WBOY
WBOYOriginal
2016-06-13 10:04:061027browse

mysql 排序
2009-10
2009-8
2009-10+2
10021-8

我想排成這樣,“—”前面的按字符由小到大排序,“—”後面的按數字由小到大排列
10021-8
2009-8
2009-10
2009-10+2

------解决方案--------------------
SELECT substring( fld1, 1, (
instr( fld1, '-' ) -1 )
) AS fld1, substring( fld1, (
instr( fld1, '-' ) +1 )
) AS fld2
FROM `table1`
ORDER BY fld1 ASC , fld2 ASC

外面那层select不要也可以
这样的话,数据量大应该也没问题吧
------解决方案--------------------

引用我想排成這樣,“—”前面的按字符由小到大排序,“—”後面的按數字由小到大排列
10021-8
2009-8
2009-10
2009-10+2
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn