oracle 简单查询

简单的查询

select

--1.查询表
select * from emp;

--2.查询某列
select ename,sal,comm
from emp;

--3.计算一年工资
select ename,sal,sal*12
from emp;

--4.计算优先级,每月有100的奖金,算全年工资
select ename,sal,(sal+100)*12
from emp;

--5.查找奖金为null的人
--在oracle查找条件中,找出null的直接使用 is null,找出不为null的使用 is not null
select * from emp
where comm is null;

--6.统计员工一年的收入,加上奖金
--方法nvl(age1,age2),当age1为null时,返回age2
select ename,sal,comm,(sal+nvl(comm,0))*12 "(月薪+奖金)*12"
from emp;

--7.起别名
select empno 编号,ename "员工名字", job as "岗位", sal as 月薪, comm "奖金"
from emp;

--8.去除重复,distinct
select distinct deptno from emp;

--9.筛选工资大于1500的员工
--比较符号 >大于号 、<小于号 、=等于号 、<>不等于号 、>=大于等于 、<=小于等于号
select * from emp
where sal>1500;

--10.筛选 工资1000到2500之间的员工
--between a and b  在a-b之间的数
select * from emp
where sal between 1000 and 2500;

--11.筛选20和30部门的员工
--in(指定的值1,指定的值2,...)
select * from emp
where deptno in(20,30);

--12.模糊查询  like
--12.01 查询名字以s开头的员工
select * from emp
where ename like 'S%';


--12.02 查询名字以s结尾的员工
select * from emp
where ename like '%S';


--12.01 查询名字中有s的员工
select * from emp
where ename like '%S%';

--13.排序  order by 列名
--13.01 工资从低到高进行排序 升序 asc (默认)
select * from emp
order by sal;


--13.02 工资从高到低进行排序 降序 desc
select * from emp
order by sal desc;

 

猜你喜欢

转载自www.cnblogs.com/whc0305/p/10145269.html