mysql按照中文名稱排序
Sql代碼 www.2cto.com
/*
Navicat MySQL Data Transfer
Source Server : local
Source Server Version : 50022
Source Host : localhost:3306
Source Database : test
Target Server Type : MYSQL
Target Server Version : 50022
File Encoding : 65001
Date: 2012-11-19 15:46:13
*/
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 李四