天天看点

mysql 中文名称排序,mysql 依照中文名称排序

mysql 按照中文名称排序

SET FOREIGN_KEY_CHECKS=0;

-- ----------------------------

-- Table structure for `person`

-- ----------------------------

DROP TABLE IF EXISTS `person`;

CREATE TABLE `person` (

`id` int(10) unsigned NOT NULL auto_increment,

`name` varchar(20) default NULL,

PRIMARY KEY (`id`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------

-- Records of person

-- ----------------------------

INSERT INTO `person` VALUES ('1', '张三');

INSERT INTO `person` VALUES ('2', '李四');

INSERT INTO `person` VALUES ('3', '王五');

INSERT INTO `person` VALUES ('4', '马六');

INSERT INTO `person` VALUES ('5', '钱七');

正序:

select * from person ORDER BY CONVERT(name USING gbk);

结果:

2李四

4马六

5钱七

3王五

1张三

倒序:

select * from person ORDER BY CONVERT(name USING gbk) desc

结果:

1张三

3王五

5钱七

4马六

2李四