Mysql之隐秘的角落
1.别名
SELECT department_name name FROM departments;
SELECT department_name 部门名称 FROM departments;
SELECT department_name "部门名称" FROM departments;
SELECT department_name "部门 名称" FROM departments;
2.DISTINCT
3.NULL
值参与运算仍未null
xxx=NULL
,可以用<=>(安全等于判断,等同于IS NULL)ISNULL()
,是个函数
4.显示表结构
1. DESCRIBE departments;
或者desc departments;
2. SHOW CREATE TABLE departments;
5.运算符
加法拼接
SELECT 100+1 FROM DUAL;
//101
SELECT 100+'1' FROM DUAL;
//101,隐式转换
SELECT 100+'a' FROM DUAL;
//100,无法转换按照0处理
除法
div
默认保留整数位
SELECT 100 div 2 FROM DUAL;
//50
SELECT 100 div 3 FROM DUAL;
//33
/
默认保留四位小数
SELECT 100/2 FROM DUAL;
//50.0000默认按照4位处理
SELECT 100/3 FROM DUAL;
//33.3333,默认保留四位小数
SELECT 100/0 FROM DUAL;
//null
6.LIKE
LIKE '%a%'
:包含a字符的LIKE '_a%'
:第二个字符包含a的LIKE '_\_a%'
:第二个字符是下划线的使用\
转移字符LIKE '_$_a%' ESCAPE '$'
:指定转义字符