SQL练习(3)(2020-04-07)

鉴于我写sql语句的能力有些差,在今后的一段时间内会时常做一些sql语句的练习。先给自己定一个小目标:先将网上能找到的sql练习都做一遍。

——————————————————————————————————————————————————————

使用oracle中的scott用户自带的几张表进行查寻出来的数据

-- 查询工资大于 1500 的所有雇员 
select * from emp where  sal > 1500;
-- 查询工资大于 1500 并且有奖金领取的雇员
select * from emp where sal > 1500 
intersect
select * from emp where comm is not null;
-- 查询工资大于 1500 或者有奖金的雇员 
select * from emp where sal > 1500
union all
select * from emp where comm != 0;
-- 查询工资不大于 1500 并且没有奖金的人
select * from emp where sal between 0 and 1500
intersect
select *  from emp where comm is null or comm = 0.0;
-- 基本工资大于 1500 但是小于 3000 的全部雇员
select * from emp where sal between 1500 and 3000;
-- 查询 1981-1-1 到 1981-12-31 号入职的雇员 
select * from emp where hiredate between to_date('1981-1-1', 'yyyy-mm-dd') and to_date('1981-12-31', 'yyyy-mm-dd');
-- 查询雇员名字叫 smith 的雇员 
select * from emp where ename = 'SMITH';
-- 查询雇员编号是 7369,7499,7521 的雇员编号的具体信息
select * from emp where empno in (7369, 7499, 7521);
-- 查询雇员姓名是’SMITH’,’ALLEN’,’WARD’的雇员具体信息
select * from emp where ename in ('SMITH','ALLEN','WARD');
-- 查询出所有雇员姓名中第二个字符包含“M”的雇员 
select * from emp where ename like '_M%';
-- 查询名字中带有“M”的雇员
select * from emp where ename like '%M%'; 
-- 查询雇员编号不是 7369 的雇员信息 不等于<> != --空值 is null ,is not null 
select * from emp where empno != 7369;
-- 查询没有奖金的员工信息
select * from emp where comm is null or comm = 0.0;
-- 查询有奖金的员工信息
select * from emp where comm != 0.0;

猜你喜欢

转载自blog.csdn.net/qq_26896085/article/details/105377474
今日推荐