100% 中的排序依据百分比移至末尾



这是我以正确的降序排列百分比的查询。

SELECT
id, 
concat(round(100 * ( count(t5.answ IN (t1.answ, t2.answ, t3.answ)) ) / case when t6.name < 4 then 100 when t6.name = 4 then 200 when t6.name > 4 then 300 end,0)) as score,
another_column
from t1
order by score desc

score输出为

91%, 96%, 100%, 92%, 

我在寻找什么

100%, 96%, 92%, 91%

但我得到的是,100% 被移到最后

order by score desc
// 96%, 92%, 91%, 100%

这是因为您按字符串而不是数字排序。 鉴于表达式的复杂性,只需转换回一个数字进行排序:

order by (score + 0) desc

最新更新