Mysql 学习之路(二)Mysql基础知识之简单查询
1.查询单个字段
select last_name from employees;
2.查询多个字段
select last_name,salary,email from employees;
3.查询所有字段
select * from employees;
4.查询常量值
select 100;
select "john";
5.查询表达式
select 100*90;
6.查询函数;
select version();
7.字段起别名
select lase_name as “姓”,first_name as "名" from employees;
8.去重
select DISTINST department_id from employees;
9.字段连接
select CONCAT(last_name,first_name) as "姓名" from employees;
10.条件查询
select * from employees where salary>12000;
select last_name,department_id from employees where department_id != 90;
select last_name,department_id from employees where salary>10000 and salary<20000;
like:
SELECT * FROM employees where last_name LIKE '%a%';(模糊查询,%包括任意多个字符,_为任意单个字符,\为转义符号)
SELECT * FROM employees where last_name LIKE '__e%';
between and
select * from employees where employee_id BETWEEN 100 and 120;
in
select * from employees where job_id in ("IT_PROT","AD_VP","AD_PRES");
is null
SELECT last_name commission_pct from employees where commission_pct is null;
SELECT last_name commission_pct from employees where commission_pct is not null;
安全等于
SELECT last_name commission_pct from employees where commission_pct <=> null;