自动生成ROWNUN
SELECT (@rowNO := @rowNo+1) AS rowno,a.uuid
FROM (SELECT * FROM h_log_proc) a,(SELECT @rowNO :=0) b
随机取记录
SELECT * FROM (SELECT (@rowNo :=@rowNo+1) AS rowno, pwd FROM pur_admininfo, (SELECT @rowNo := 0) b) tmp WHERE rowno=(SELECT ROUND(RAND() * 10000000 % (SELECT COUNT(*) FROM pur_admininfo))) LIMIT 1
去除水平制表符
#查询
#SELECT * FROM web_h_cus_info WHERE LOCATE(CHAR(10),address)>0;
#去除换行回车符
UPDATE `web_h_cus_info` SET `address` = REPLACE(REPLACE(`address`, CHAR(10),''), CHAR(13),'');
#去除空格
UPDATE `web_h_cus_info` SET `address`=REPLACE(`address`,' ','');
#去除水平制表符
UPDATE `web_h_cus_info` SET `address`=REPLACE(`address`,CHAR(9),'');
返回第一个为空元素
SELECT COALESCE(NULL,NULL,3,4,5)
--返回3
比较两个字符串
STRCMP(str1, str2)
比较两个字符串,如果这两个字符串相等返回0,如果第一个参数是根据当前的排序小于第二个参数顺序返回-1,否则返回1。
返回输入参数(n1, n2, n3, 等)组的最大值
GREATEST(n1,n2,n3,..........)
GREATEST()函数返回输入参数(n1, n2, n3, 等)组的最大值。下面的示例使用 GREATEST()函数从一组数字值中返回最大的值:
返回最小值
LEAST('B','A','C');
把一列值,合并成用","隔开的字符串
GROUP_CONCAT([DISTINCT] expr [,expr ...]
[ORDER BY {unsigned_integer | col_name | expr}
[ASC | DESC] [,col_name ...]]
[SEPARATOR str_val])