2 ways to sort the Chinese data in Mysql by pinyin _mysql

Source: Internet
Author: User

Customer service There is a need for me to some hotels in Chinese pinyin sorting, has not previously contacted, in the PHP group asked some Daniel. You get 2 answers, all of them. haha ~
The following is a MSYQL example, the table structure is utf-8

Method One,

Copy Code code as follows:

SELECT ' Hotel_name '
From ' Hotel_base '
ORDER by convert (' Hotel_name '
USING GBK)
COLLATE Gbk_chinese_ci

method Two,
Copy Code code as follows:

SELECT ' hotel_id ', ' Hotel_name ', ELT (INTERVAL (CONV HEX (' Hotel_name ')
USING GBK), 1)), 0xb0a1, 0xb0c5, 0xb2c1, 0xb4ee, 0xb6ea, 0XB7A2, 0xb8c1, 0xb9fe, 0xbbf7, 0xbfa6, 0xc0ac, 0 Xc2e8, 0XC4C3, 0xc5b6, 0xc5be, 0xc6da, 0XC8BB, 0xc8f6, 0xCBFA, 0xCDDA, 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 Hotel_base
ORDER BY PY ASC

Method One more simple oh hope to the confused people have help ~ ~ ~

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.