簡體   English   中英

mysql 按某些條件排序且不區分大小寫

[英]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,B,C,a,b,c)

我想要結果為 (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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM