查看正在执行的sql语句 show processlist; 停止正在执行的sql语句 kill id(正在执行的sqlID); 查询的时候增加一个字符串一起返回 SELECT CONCAT("strvalue") AS str table; 表修复 myisamchk -r table 获取表字段名称和注释 SELECT COLUMN_NAME,COLUMN_COMMENT FROM INFORMATION_SCHEMA.Columns WHERE table_name='table_name'; 查询表结构, 所有字段和属性 SELECT * FROM INFORMATION_SCHEMA.Columns WHERE table_name='table_name' 中文按照首字母排序 SELECT * FROM table ORDER BY CONVERT(nickname USING gbk) asc; 整数值、表结构字符串类型 转为整数进行排序 SELECT * FROM table ORDER BY CONVERT(code, SIGNED) asc;
中英文混合排序
写一个方法获取第一个字符,中文则转为字母,字母或数字则截取第一个字母返回
# 方法 CREATE FUNCTION `MY_FIRST_PINYIN`(P_NAME VARCHAR(255)) RETURNS varchar(255) CHARSET utf8 COMMENT '中文首字母转拼音' BEGIN DECLARE V_RETURN VARCHAR(255); SET V_RETURN = ELT(INTERVAL(CONV(HEX(LEFT(CONVERT(P_NAME USING gbk),1)),16,10), 0xB0A1,0xB0C5,0xB2C1,0xB4EE,0xB6EA,0xB7A2,0xB8C1,0xB9FE,0xBBF7, 0xBFA6,0xC0AC,0xC2E8,0xC4C3,0xC5B6,0xC5BE,0xC6DA,0xC8BB, 0xC8F6,0xCBFA,0xCDDA,0xCEF4,0xD1B9,0xD4D1), 'A','B','C','D','E','F','G','H','J','K','L','M','N','O','P','Q','R','S','T','W','X','Y','Z'); IF ISNULL(V_RETURN) THEN SET V_RETURN = LEFT(P_NAME,1); END IF; RETURN UPPER(V_RETURN); END; # 查询语句 SELECT * FROM table ORDER BY MY_FIRST_PINYIN(nickname) asc;
发表评论: