一.流程函数
-- 创建表来介绍 CREATE TABLE salary (userid INT,salary DECIMAL(9,2)); INSERT INTO salary VALUES(1,1000),(2,2000), (3,3000),(4,4000),(5,5000), (1,NULL); SELECT * FROM salary
1. if(value,t,f) 超过2000的用high,否则用low
SELECT IF(salary>2000 ,‘high‘,‘low‘) FROM salary
2. ifnull(value1,value2) 下面语句是把null值替换0
SELECT IFNULL(salary,0) FROM salary;
3.case when ... 用来实现中高低薪的问题
SELECT CASE WHEN salary<=2000 THEN ‘low‘ WHEN salary>=2001 AND salary<=4000 THEN‘middle‘ ELSE ‘high‘ END FROM salary;
二. 其它常用函数
SELECT DATABASE() AS ‘数据库名‘, VERSION() AS ‘数据库版本‘, USER() AS ‘当前用户名‘, INET_ATON(‘192.168.1.1‘)AS ‘IP字节‘, INET_NTOA(3232235777) AS ‘ip字节转IP‘
2. PASSWORD 返回加密后的字符,一般用来设置系统用户的密码
SELECT PASSWORD(‘123456‘)
3. md5(str) 对一般应用数据加密
SELECT MD5(‘123456‘);
原文地址:https://www.cnblogs.com/MrHSR/p/9247310.html
时间: 2024-10-10 06:06:48