利用中文拼音首字母查询数据库

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的结果

posted @ 2017-04-12 17:26  Nullnullisnull  阅读(1690)  评论(0)    收藏  举报