最终要实现效果,如下:

QQ截图20170331095227

"mysql查询语句"

SELECT t1.id, t1.name, t2.f_PY
FROM table_name t1, table_coslers t2
WHERE CONV(HEX(LEFT(CONVERT(t1.name USING gbk ), 1)), 16, 10) BETWEEN t2.cBegin AND t2.cEnd
ORDER BY convert(t1.name using gbk) ASC

数据库需要2张表:
1.姓名表(table_name),包含字段,id,name ,自行手动建立
2.查询汉字区间表(table_coslers)。建表语句如下:

/*
Navicat MySQL Data Transfer

Target Server Type    : MYSQL
Target Server Version : 50617
File Encoding         : 65001

Date: 2015-07-02 11:12:15
*/

SET FOREIGN_KEY_CHECKS=0;

-- ----------------------------
-- Table structure for t_coslers
-- ----------------------------
DROP TABLE IF EXISTS `t_coslers`;
CREATE TABLE `t_coslers` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `f_PY` char(1) CHARACTER SET utf8 DEFAULT NULL,
  `cBegin` smallint(5) unsigned NOT NULL,
  `cEnd` smallint(5) unsigned NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=24 DEFAULT CHARSET=latin1;

-- ----------------------------
-- Records of t_coslers
-- ----------------------------
INSERT INTO `t_coslers` VALUES ('1', 'A', '45217', '45252');
INSERT INTO `t_coslers` VALUES ('2', 'B', '45253', '45760');
INSERT INTO `t_coslers` VALUES ('3', 'C', '45761', '46317');
INSERT INTO `t_coslers` VALUES ('4', 'D', '46318', '46825');
INSERT INTO `t_coslers` VALUES ('5', 'E', '46826', '47009');
INSERT INTO `t_coslers` VALUES ('6', 'F', '47010', '47296');
INSERT INTO `t_coslers` VALUES ('7', 'G', '47297', '47613');
INSERT INTO `t_coslers` VALUES ('8', 'H', '47614', '48118');
INSERT INTO `t_coslers` VALUES ('9', 'J', '48119', '49061');
INSERT INTO `t_coslers` VALUES ('10', 'K', '49062', '49323');
INSERT INTO `t_coslers` VALUES ('11', 'L', '49324', '49895');
INSERT INTO `t_coslers` VALUES ('12', 'M', '49896', '50370');
INSERT INTO `t_coslers` VALUES ('13', 'N', '50371', '50613');
INSERT INTO `t_coslers` VALUES ('14', 'O', '50614', '50621');
INSERT INTO `t_coslers` VALUES ('15', 'P', '50622', '50905');
INSERT INTO `t_coslers` VALUES ('16', 'Q', '50906', '51386');
INSERT INTO `t_coslers` VALUES ('17', 'R', '51387', '51445');
INSERT INTO `t_coslers` VALUES ('18', 'S', '51446', '52217');
INSERT INTO `t_coslers` VALUES ('19', 'T', '52218', '52697');
INSERT INTO `t_coslers` VALUES ('20', 'W', '52698', '52979');
INSERT INTO `t_coslers` VALUES ('21', 'X', '52980', '53640');
INSERT INTO `t_coslers` VALUES ('22', 'Y', '53689', '54480');
INSERT INTO `t_coslers` VALUES ('23', 'Z', '54481', '55289');

centos yum安装mysql5.7 或 mysql8.0

参考:http://www.koukousky.com/back/1296.html 参考:https://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/ $ wget https://dev.mysql.com/get/mysql...

阅读全文

Mysql 分页优化

在系统中需要进行分页的时候,我们通常会使用limit 加上偏移量的方法实现,再加上合适的order by 子句,如果有对应的索引,通常效率会很不错,否则mysql需要...

阅读全文

MySQL 5.7以上 root用户默认密码问题【转】

转载地址:https://www.yanning.wang/archives/379.html 最近有点小问题,需要在本地虚拟机里搭建一个MySQL服务器.但是按着以前的日志一步步操作,最后总是...

阅读全文

欢迎留言