Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何对id的widt dot进行排序。我有这张桌子: 1, 1.2, 2, 3, 3.1, 3.2, 4, 5, 100, 101, 200 ...
1, 1.2, 2, 3, 3.1, 3.2, 4, 5, 100, 101, 200 ...
如果我们使用SELECT * FROM table ORDER BY id ASC它会显示: 1, 100, 101, 1.2, 2, 200, 3, 3.1, 3.2, 4, 5 ...
SELECT * FROM table ORDER BY id ASC
1, 100, 101, 1.2, 2, 200, 3, 3.1, 3.2, 4, 5 ...
但我需要这个: 1, 1.2, 2, 3, 3.1, 3.2, 4 ,5, 100, 101, 200 ...
1, 1.2, 2, 3, 3.1, 3.2, 4 ,5, 100, 101, 200 ...
尝试这个::
SELECT * FROM table ORDER BY CAST(id AS DECIMAL) ASC
您可以做的其他事情是将数据库中的列设为 FLOAT
然后你像在没有 CAST 的 sql 中一样订购你的数字
它会起作用