拼接函数
select concat(first_name,last_name) as "姓 名" from employees;
将名和姓进行拼接
如果拼接的字段中有null值,则需要使用ifnull函数否则含有空值的字段为null
select concat(first_name,last_name,ifnull(employees_pct,"空")) demo from employees;
去重函数
select distinct department_id from employees;
将重复的员工编号去重
条件查询
select * from table where id >100;
执行顺序:
1.from子句
2.where子句
3.select子句
特点:
1.按照关系表达式筛选
关系运算符:> < >= <= !=(不建议使用) <>
2.按逻辑表达式筛选
逻辑运算符:and(and两边都成立为true) or(or一边成立为true) not(取反)
也可以使用&& || !
3.模糊查询(一般和通配符一起使用)
like
in:查询某字段的值是否属于指定列表之内 in(值1,值2,值3。。。)
between and:判断某个字段的值是否介于xx之间
is null
查询姓名中包含第二个字符为_的员工信息
常见通配符
_任意单个字符
%任意多个字符(0-多个)
select * from employees where last_name like '_\_%';
遇到特殊字符需要转义符号
查询部门编号是30-90之间的部门编号和员工姓名
select department_id,last_name from employees where department_id between 30 and 90;