Implementation of querying the first letter of Chinese characters and Pinyin in MySQL

Source: Internet
Author: User
Tags mysql functions

The following describes how to query the initials of Chinese characters and Pinyin in MySQL. This method is very useful. If you have encountered similar problems before, take a look.

To query the initials of Chinese characters and Pinyin in MySQL, follow these steps:

1. Create a pinyin initials data table
SQL code:
Drop table if exists 'pinin ';
Create table 'pinin '(
'Py' varchar (1 ),
'Hz1 'varchar (1 ),
'Hz2' varchar (1)
);

Insert into 'pinin' ('py', 'hz1 ', 'hz2') VALUES
('A', 'tag', 'tag '),
('B', '8', 'book '),
('C', 'hangzhou', 'hangzhou '),
('D', 'taobao', 'taobao '),
('E', 'hangzhou', 'hangzhou '),
('F', 'F', 'hangzhou '),
('G', 'hangzhou', 'hangzhou '),
('H', 'hangzhou', 'hangzhou '),
('J', 'day', 'hangzhou '),
('K', 'hangzhou', 'hangzhou '),
('L', 'hangzhou', 'hangzhou '),
('M', 'M', 'M '),
('N', 'hangzhou', 'hangzhou '),
('O', 'ou', 'hangzhou '),
('P', 'taobao', 'exposing '),
('Q', '7', 'q '),
('R', 'hangzhou', 'hangzhou '),
('S ', 'alipay', 'alipay '),
('T', 'Ta', 'hangzhou '),
('W', 'two', 'two '),
('X', 'Xi ', 'hangzhou '),
('Y', 'ya ', 'taobao '),
('Z', 'taobao', 'taobao ');

After execution, check whether there are "?" data records in the added table. Question mark. If yes, the database encoding is incorrect.
PY HZ1 HZ2
A challenge
B
C branch networks
D zookeeper
E branch networks
F producer
G branch networks
H branch networks
J.
K branch networks
L zookeeper
M branch networks
N branch networks
O
P branch exposure
Q qizhen
R branch networks
S branch networks
T he Yi
W Yunxiao
X Xi Jinping
Y Branch
Z branch networks

2. MySQL queries the first Chinese Character and alphabet in the database table
SELECT 'pinyin'. py, 'corresponding Table '.*
FROM 'corresponding table', 'pinin'
WHERE 'Chinese character title'> = 'hz1'
AND 'Chinese character title' <= 'hz2 ';

Example of query results:
 
Py Chinese Character title
Z recruitment
Z topics
W website Introduction
W ask
S search
L contact information
L Forum
H Member
G about us
B. Copyright Notice
Encyclopedia B

You can also directly use MySQL to query the first Chinese Character and alphabet of Chinese characters.
SELECT 'pinin'. py
FROM 'pinin'
WHERE 'Chinese character '> = 'hz1'
AND 'Chinese characters' <= 'hz2 ';

The query result is "H"


 

MySQL table lock status and number of opened files

View the processes of the MySQL server

How to enable MySQL slow Query

Mysql multi-Table query implementation

How to Create MySQL Functions

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.