利用中文拼音首字母查詢數據庫


1.創建表

CREATE TABLE `x_ch2en` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `ch` varchar(20) DEFAULT NULL COMMENT '中文',
  `en` varchar(20) DEFAULT NULL COMMENT '中文對應的字母',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=32 DEFAULT CHARSET=utf8 COMMENT='中文對應字母表';

2.插入中英對照數據

insert   into   x_ch2en(ch,en)   
select   '', 'A '   union   all   select   '', 'B '   union   all   
select   '', 'C '   union   all   select   '', 'D '   union   all   
select   '', 'E '   union   all   select   '', 'F '   union   all   
select   '', 'G '   union   all   select   '', 'H '   union   all   
select   '', 'J '   union   all   select   '', 'K '   union   all   
select   '', 'L '   union   all   select   '', 'M '   union   all   
select   '', 'N '   union   all   select   '', 'O '   union   all   
select   '', 'P '   union   all   select   '', 'Q '   union   all   
select   '', 'R '   union   all   select   '', 'S '   union   all   
select   '', 'T '   union   all   select   '', 'W '   union   all   
select   '', 'X '   union   all   select   '', 'Y '   union   all   
select   '', 'Z '

3.用 where user_name>='' and user_name <'八' 來查詢中首字母為A的結果


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM