查询语句
select * from t_dept
select empno,ename,sal from t_emp
select
empno,
sal * 12 as "income"
from t_emp
分页
select empno,ename from t_emp limit 10,5
去除重复字段
select job from t_emp 会出现重复的
CLERK
SALESMAN
SALESMAN
MANAGER
SALESMAN
MANAGER
MANAGER
ANALYST
PRESIDENT
select DISTINCT job from t_emp 加上关键字 DISTINCT 就不会出现重复 只能使用一个字段
CLERK
SALESMAN
MANAGER
ANALYST
PRESIDENT
排序 DESC 降序 ASC升序
select empno,ename,sal,deptno from t_emp ORDER BY sal DESC
条件查询
select empno,ename,sal,deptno from t_emp where deptno in (10,20) and sal >= 2000 order by deptno
select empno,ename,sal,hiredate,deptno
from t_emp
where deptno = 10
AND (sal + IFNULL(comm,0))* 12 > 15000
AND DATEDIFF(NOW(),hiredate)/365 >= 20
select empno,ename,sal,hiredate,deptno
from t_emp
where deptno in (10,20,30) and job != 'SALESMAN'
is null / is not null
select empno,ename,sal,hiredate,deptno,comm
from t_emp
where comm is null
BETWEEN ... AND ...
select empno,ename,sal,hiredate,deptno,comm
from t_emp
where comm is null
AND sal BETWEEN 2000 AND 3000
LIKE 模糊查询
select empno,ename,sal,hiredate,deptno,comm
from t_emp
where comm is null
AND sal BETWEEN 2000 AND 3000
AND ename LIKE '%A%'