-- 创建EMP表
CREATE TABLE EMP
(
EMPNO int(4) PRIMARY KEY,
ENAME VARCHAR(10),
JOB VARCHAR(9),
MGR INT(4),
HIREDATE DATE,
SAL DOUBLE(7,2),
COMM DOUBLE(7,2),
DEPTNO INT(2)
);
-- where查询 语句
SELECT * from emp;
-- 模糊查询
-- 搜索emp表中还有A的员工信息
SELECT * FROM emp where ENAME like '%A%';
-- 匹配ename中用A开头的员工信息
SELECT * FROM emp where ENAME like 'A%';
-- 匹配ename中用A结尾的的员工信息
SELECT * FROM emp where ENAME like '%A';
-- 匹配ename中第二个字符为A的的员工信息
SELECT * FROM emp where ENAME like '_A%';
-- is null 判断是否为空
-- 查询所有没有加班费的员工信息
SELECT * from emp where COMM is null;
SELECT * from emp where COMM is not null;
-- 小括号,增强可阅读性
SELECT * FROM emp where ENAME='WARD' OR ENAME='ALLEN' AND SAL>7500;
SELECT * FROM emp where ENAME='WARD' OR (ENAME='ALLEN' AND SAL>7500);