from college_schlist p , t_cosler c
where CONV(HEX(left(convert(school_name using gbk),1)),16,10) between c.cBegin and c.cEnd
and c.f_PY='A';
新建一个t_cosler,拼音的对照表,跟着这个表关联查询数据
DROP TABLE IF EXISTS `t_cosler`;
CREATE TABLE `t_cosler` (
`f_PY` char(255) NOT NULL,
`cBegin` int(11) NOT NULL,
`cEnd` int(11) DEFAULT NULL,
PRIMARY KEY (`f_PY`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
INSERT INTO `t_cosler` VALUES ('A', '45217', '45252');
INSERT INTO `t_cosler` VALUES ('B', '45253', '45760');
INSERT INTO `t_cosler` VALUES ('C', '45761', '46317');
INSERT INTO `t_cosler` VALUES ('D', '46318', '46825');
INSERT INTO `t_cosler` VALUES ('E', '46826', '47009');
INSERT INTO `t_cosler` VALUES ('F', '47010', '47296');
INSERT INTO `t_cosler` VALUES ('G', '47297', '47613');
INSERT INTO `t_cosler` VALUES ('H', '47614', '48118');
INSERT INTO `t_cosler` VALUES ('J', '48119', '49061');
INSERT INTO `t_cosler` VALUES ('K', '49062', '49323');
INSERT INTO `t_cosler` VALUES ('L', '49324', '49895');
INSERT INTO `t_cosler` VALUES ('M', '49896', '50370');
INSERT INTO `t_cosler` VALUES ('N', '50371', '50613');
INSERT INTO `t_cosler` VALUES ('O', '50614', '50621');
INSERT INTO `t_cosler` VALUES ('P', '50622', '50905');
INSERT INTO `t_cosler` VALUES ('Q', '50906', '51386');
INSERT INTO `t_cosler` VALUES ('R', '51387', '51445');
INSERT INTO `t_cosler` VALUES ('S', '51446', '52217');
INSERT INTO `t_cosler` VALUES ('T', '52218', '52697');
INSERT INTO `t_cosler` VALUES ('W', '52698', '52979');
INSERT INTO `t_cosler` VALUES ('X', '52980', '53640');
INSERT INTO `t_cosler` VALUES ('Y', '53689', '54480');
INSERT INTO `t_cosler` VALUES ('Z', '54481', '55289');
转载请注明:谷谷点程序 » mysql 根据拼音首字母查询数据