Two methods for sorting mysql Chinese data by pinyin _ MySQL
Source: Internet
Author: User
Two methods of sorting mysql Chinese data by pinyin customer service I need to sort Chinese pinyin for some hotels. I have never touched it before and asked some experts in the php Group .. You can obtain either of the two answers. Haha ·~
The following is an example of msyql. the table structure is UTF-8
I found a server to set up the magnetic link crawler http://www.51bt.cc (51 search) you can see.
Method 1,
The code is as follows:
SELECT 'Hotel _ name'
FROM 'Hotel _ base'
Order by convert ('Hotel _ name'
USING gbk)
COLLATE gbk_chinese_ci
Method 2,
The code is as follows:
SELECT 'Hotel _ id', 'Hotel _ name', ELT (INTERVAL (CONV (HEX (left (CONVERT ('Hotel _ name'
USING gbk), 1), 16, 10), 0xB0A1, 0xB0C5, 0xB2C1, 0xB4EE, 0xB6EA, 0xB7A2, 0xB8C1, 0xB9FE, 0xBBF7, primary, 0xC0AC, primary, 0xC4C3, 0xC5B6, 0xC5BE, 0xC6DA, 0xC8BB, 0xC8F6, 0 xCBFA, 0 xCDDA, 0xCEF4, 0xD1B9, 0xD4D1), 'A', 'B', 'C', 'D ', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'n', 'O ', 'P', 'Q', 'R','s ', 'T', 'W', 'X', 'y', 'z') AS PY
FROM pai_base
ORDER BY PY ASC
Method 1 is easier than method 2. hope to help confused people ~~~
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.