基本操作
SELECT LENGTH('john');
SELECT LENGTH('张三丰hahaha');
SHOW VARIABLES LIKE '%char%';
SELECT CONCAT(last_name,'_',first_name)
FROM employees;
SELECT UPPER('john');
SELECT CONCAT(UPPER(last_name),'_',LOWER(first_name))
FROM employees;
SELECT SUBSTR('李莫愁爱上了陆展元',7) AS love;
SELECT SUBSTR('李莫愁爱上了陆展元',1,3) AS love;
SELECT CONCAT(UPPER(SUBSTR(last_name,1,1)),'_',LOWER(SUBSTR(last_name,2))) AS 名字
FROM employees;
SELECT INSTR('杨不悔爱上了殷六侠','殷六侠') AS love;
SELECT TRIM(' 张翠山 ') AS out_put;
SELECT TRIM('h'FROM'hhhhhhhh张翠山hhhhhhhhhhhhh') AS out_put;
SELECT LPAD('殷素素',10,'*') AS love;
SELECT RPAD('殷素素',10,'*') AS love;
SELECT REPLACE('张无忌爱上了周芷若','周芷若','赵敏');
SELECT ROUND(1.45);
SELECT ROUND(-1.45);
SELECT ROUND(-1.457,2);
SELECT CEIL(1.45);
SELECT FLOOR(1.45);
SELECT TRUNCATE(1.455555,1);
SELECT MOD(12,5);
SELECT 12%5;
SELECT MOD(-12,5);
SELECT NOW();
SELECT CURDATE();
SELECT CURTIME();
SELECT YEAR(NOW()) AS 年;
SELECT YEAR('1998-1-1') AS 年;
SELECT YEAR(hiredate) AS 年
FROM employees;
SELECT MONTH(NOW()) AS 月;
SELECT MONTHNAME(NOW()) AS 月;
SELECT STR_TO_DATE('1998-3-2','%Y-%c-%d');
SELECT * FROM employees WHERE hiredate='1992-4-3';
SELECT * FROM employees WHERE hiredate=STR_TO_DATE('4-3 1992','%c-%d %Y');
SELECT DATE_FORMAT(NOW(),'%Y年%c月%d日') AS out_put;
SELECT last_name,DATE_FORMAT(hiredate,'%c月/%d日 %y年')
FROM employees
WHERE commission_pct IS NOT NULL;
SELECT VERSION();
SELECT DATABASE();
SELECT USER();
SELECT IF(10<5,'大','小');
SELECT last_name,commission_pct,
IF(commission_pct IS NULL,'没奖金,哈哈','有奖金,嘻嘻') AS 备注
FROM employees;
SELECT salary AS 原始工资,department_id,
CASE department_id
WHEN 30 THEN salary*1.1
WHEN 40 THEN salary*1.2
WHEN 50 THEN salary*1.3
ELSE salary
END AS 新工资
FROM employees;
SELECT salary,
CASE
WHEN salary>20000 THEN 'A'
WHEN salary>15000 THEN 'B'
WHEN salary>10000 THEN 'C'
ELSE 'D'
END AS 工资的级别
FROM employees;