2 回答
TA贡献1856条经验 获得超17个赞
当您对它们应用算术运算(如加法)时, SQLite会将字符串文字隐式转换为数字。因此,当您执行以下操作时,
它将转换50MB为: 。 所以相加的结果将是。 所以你可以这样做:5050MB + 0
50
SELECT * FROM filtered
ORDER BY
case
when size like '%TB%' then 1
when size like '%GB%' then 2
when size like '%MB%' then 3
when size like '%kB%' then 4
when size like '%B%' then 5
else 6
end,
size + 0 desc
或者只有 1 级排序:
SELECT * FROM filtered
ORDER BY
size * case
when size like '%TB%' then 1024 * 1024 * 1024 * 1024
when size like '%GB%' then 1024 * 1024 * 1024
when size like '%MB%' then 1024 * 1024
when size like '%kB%' then 1024
when size like '%B%' then 1
else 1
end desc
TA贡献1863条经验 获得超2个赞
您可以CAST
选择size
a FLOAT
(因为它以数字开头),然后将其用作次要ORDER BY
标准,即:
SELECT * FROM filtered ORDER BY case when size like '%TB%' then 1 when size like '%GB%' then 2 when size like '%MB%' then 3 when size like '%kB%' then 4 when size like '%B%' then 5 else 6 end, CAST(size AS FLOAT) DESC
添加回答
举报