--1.语法 select [distinct]*|列名称[别名],列名称[别名]... from 表名 [别名] --执行顺序: 1.from子句,然后select子句; distinct 如果查询的是多个列,只有在多个列都完全重复的时候才可以消除重复; |
---|
--1.查询emp中的所有数据 select * from emp; --2.查询emp表中的雇员的编号,姓名,职位,工资; select e.empno,e.ename,e.job,e.sal from emp e; --3.消除名字相同的数据 select distinct(ename) from emp; select distinct from emp;--查询所以列都不相同的数据 select distinct ename from emp;--查询名字不同的员工的名字 select distinct(ename),sal from emp;---查询不同名字的员工的姓名和工资; select e.empno,e.ename from emp e; --4查询每个雇员的编号、姓名、基本年薪(13薪,每年领5个月的高温补贴1000,每个月领500交通补贴) select e.empno,e.ename,sal*13+1000+500*12 sal from emp e; |
--5.常量 1.字符串 用","声明 2.数字 直接编写 3.日期 使用日期格式 --5.1直接查询常量 select '雇员',empno,ename from emp; --5.2"||" 连接 select '姓名 : '||ename ||',工资:' ||sal say from emp;select * from emp; |
--6.四则运算 ---查询员工的姓名,年薪(15薪+每个月500交通补贴+每个月300的饭补) select e.ename,sal*12+500*12+300*12 sal from emp e; |
--限定查询 select [distinct]*|列名称[别名],列名称[别名]... from 表名 [别名] [where] 条件 1.确定数据来源 from 2.确定满足数据的数据行 where 3.控制要显示的数据列 select 限定查询的符合 1.关系运算符:>,<,<=,>=,<>(!=); 2.逻辑运算符:AND,OR,NOT 3.范围运算符:BETWEEN...AND,IN,NOT IN; 4.空判断:IS NULL,IS NOT NULL 5.模糊查询:LIKE "="可以在数字上使用,也可以在字符串中使用 |
--1.查询工资高于1500的员工信息 |
--空判断:is null ;is not null select * from emp e where comm is not null;---查询由佣金的员工信息 |
--7.order by 分组查询 --连接字符 |