Oracle必会SQL语句(一)

—查询所有的内容

 select * from emp

—查询编号,姓名,工作

select empno,ename,job from emp

—分别取别名

select empno 编号,ename 姓名,job 工作 from emp

—查询所有员工的工作

select job from emp

—查询所有工作(去除重复)

 select distinct job from emp

—去除员工编号和工作重复的组合

select distinct empno,job from emp

—查询员工编号,姓名,工作,但是根据特定的显示格式

select '编号是:'||empno||'的雇员,姓名是:'||ename||'工作是:'||job from emp

—求出每个雇员的姓名及年薪(income:收入,收益)

select ename,sal*12 income from emp

—求出工资大于1500的所有雇员信息

select * from emp where sal>1500

—查询出没有奖金的雇员信息

select * from emp where comm is null

—查询出基本工资大于1500同时可以领取奖金的雇员信息

select * from emp  where sal>1500 and comm is not null
select * from emp  where sal>1500 and comm is not null

—查询出基本工资大于1500或者可以领取奖金的雇员信息

select * from emp where sal>1500 or comm is not null

—查询出基本工资不大于1500或者不可以领取奖金的雇员信息

select * from emp where not(sal>1500 or comm is not null)

—查询出基本工资大于1500,但是小于3000的全部雇员信息

select * from emp where sal>1500 and sal<3000

—查询基本工资大于等于1500,但是小于等于3000的全部雇员信息

select * from emp where sal>=1500 and sal<=3000

—查询出在1981年雇佣的全部员工信息

select * from emp where hiredate like '%81%' 
select * from emp where hiredate>=to_date('1981-01-01','YYYY-MM-DD')
    and hiredate<to_date('1982-01-01','YYYY-MM-DD')

—查询出姓名是smith的雇员信息

select * from emp where ename='SMITH'

—查询出雇员是7369,7499,7521的雇员信息

select * from emp where empno=7369 or empno=7499 or empno=7521
select * from emp where empno  in(7369,7499,7521)

—查询出雇员不是7369,7499,7521的雇员信息

select * from emp where not(empno=7369 or empno=7499 or empno=7521)  
select * from emp where empno not in(7369,7499,7521)  

—查询出雇员姓名是smith,allen,king的雇员信息

select * from emp where ename='SMITH' or ename='ALLEN' or ename='KING' select * from emp where ename in('SMITH','ALLEN','KING')

—查询出所有雇员姓名中第二个字母包含M的雇员信息

select * from emp where ename like '_M%'

—查询出所有雇员小名中包含字母M的雇员信息

select * from emp where ename like '%M%'

—查询工资中包含5的雇员信息

select * from emp where sal like '%5%'

—查询雇员编号不是7369的雇员信息

select * from emp where not (empno=7369) 
select * from emp where empno != 7369

—要求按照工资由低到高排序

select * from emp order by sal asc  select * from emp order by sal

—要求按照工资由高到低排序

 select * from emp order by sal desc

—要求查询出20部门的所有雇员信息,查询出的信息按照工资由高到低排序,如果工资相等,则按照雇佣日期有早到晚排序

select * from emp where deptno=20 order by sal desc,hiredate asc
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值