简体   繁体   English

按敏感大写字母排序

[英]Order by sensitive capital letter

I have some entries in my table:我的表中有一些条目:

id txt
1 phone
2 phone
3 phone
4 Phone
5 Phone
6 PHONE
7 phone
8 aaa
9 ZZZ
10 ééé

and I have this request我有这个要求

select * from table order upper(txt) collate utf8_bin

8 aaa 10 ééé 1 phone 2 phone 3 phone 4 Phone 5 Phone 6 PHONE 7 phone 9 ZZZ 8 aaa 10 ééé 1 电话 2 电话 3 电话 4 电话 5 电话 6 PHONE 7 电话 9 ZZZ

I need to do an other order, which entry (1,2,3,4,5,6,7) was order a sensitive case, with the capital letter before我需要做另一个订单,其中条目 (1,2,3,4,5,6,7) 是订单敏感案例,前有大写字母

I want this result:我想要这个结果:

8 aaa
10 ééé
6 PHONE ===> CAPITAL
4 Phone ===> Capital
5 Phone ===> Capital
1 phone
2 phone
3 phone
7 phone
9 ZZZ

and also I need to use collate collate utf8_bin而且我还需要使用 collat​​e collat​​e utf8_bin

Use this as your ORDER BY clause.将此用作您的 ORDER BY 子句。 This will first order all of the txt case insensitive, to get all names in order.这将首先对所有不区分大小写的 txt 进行排序,以按顺序获取所有名称。 Then it will sort case sensitively (binary) in DESC order to put identical lower case names first.然后它将按 DESC 顺序区分大小写(二进制),以首先放置相同的小写名称。 The binary sorting would put capital letters before lowercase ones, that's why you need to use DESC.二进制排序会将大写字母放在小写字母之前,这就是您需要使用 DESC 的原因。

ORDER BY txt, binary(txt) DESC

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM