[英]mysql order by some condition and case insensitive
我想排序
“特殊字符-數字-字母-其他-空格”
SELECT title FROM table ORDER BY (case when ASCII(SUBSTRING(title, 1)) = 0 then 9 when (ASCII(SUBSTRING(title, 1)) >= 33 and ASCII(SUBSTRING(title, 1)) <= 47) then 1 when (ASCII(SUBSTRING(title, 1)) >= 58 and ASCII(SUBSTRING(title, 1)) <= 64) then 2 when (ASCII(SUBSTRING(title, 1)) >= 91 and ASCII(SUBSTRING(title, 1)) <= 96) then 3 when (ASCII(SUBSTRING(title, 1)) >= 123 and ASCII(SUBSTRING(title, 1)) <= 126) then 4 when (ASCII(SUBSTRING(title, 1)) >= 48 and ASCII(SUBSTRING(title, 1)) <= 57) then 5 when ASCII(SUBSTRING(title, 1)) > 128 then 7 when ASCII(SUBSTRING(title,1)) = 32 then 8 else 6 end ),binary(title)";
我有這個查詢想要的結果。
我想要結果為 (A, a, B, b, C, c)
做你想做的事是非常困難的。 我建議稍微放松一下你的約束,並且只遵循 ascii 順序,除了將空格更改為一些高字符:
ORDER BY REPLACE(title,' ',CONVERT(_utf32 0x10FFFF USING utf8mb4)),BINARY(title);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.