Oracle基本查询

--1.员工转正后,工资上调20%,查询所有员工转正后的工资.
select employee_id,first_name,last_name,salary as 转正前工资 ,salary*1.2 as 转正后工资
from employees
where months_between(sysdate,hire_date)>3;
--2查询员工的年薪,年薪包括年终奖,5000,和员工的提成。提成为年薪的百分比。如
--果没有提成,则不计算。
select employee_id,first_name,last_name,to_char((salary*12+5000)+salary*12*NVL(commission_pct,0),'L999,999,999.9') as 年薪
from employees;


--3.查询60号部门中工资超过6000的员工信息,包括的信息为员工的id,全名,入职的周
--数,入职月数。和作为正式员工的时间。
select employee_id,first_name||' '||last_name as 全名,round((sysdate-hire_date)/7) 入职周数,
round(months_between(sysdate,hire_date)) 入职月数,add_months(hire_date,3) 正式员工日期
from employees
where department_id=60;
--4.找出各月倒数第三天受雇的所有员工。
select *
from employees
where last_day(hire_date)-2=hire_date;
--5.找出早于12年前受雇的员工
--第一种
select *
from employees
where (sysdate-hire_date)/(365+365+365+366)>=3;
--第二种
select *
from employees
where (months_between(sysdate,hire_date))/12>12;
--6.显示满15年服务年限的员工的姓名和受雇日期
select first_name||' '||last_name as 姓名, hire_date 受雇日期
from employees
where (months_between(sysdate,hire_date))/12>=15;
--7.显示员工的姓名和受雇日期,根据其服务年限,将最老的员工排在最前面
select first_name||' '||last_name as 姓名, hire_date  受雇日期 
from employees
order by hire_date;
--8.显示所有员工姓名、加入公司的年份和月份,按受雇日期所在月排序,若月份相同则将
--最早年份的员工排在最前面。
select first_name||' '||last_name as 姓名,to_char(hire_date,'YYYY') as 加入公司年份,
to_char(hire_date,'MM') as 加入公司月份
from employees
order by to_char(hire_date,'MM'),to_char(hire_date,'YYYY');
--9以年月日的方式显示所有员工的服务年限
--第一种
select employee_id ,trunc(months_between(sysdate,hire_date)/12) 年,trunc((months_between(sysdate,hire_date)-(trunc(months_between(sysdate,hire_date)/12))*12)) 月, 
round(sysdate-add_months(hire_date,trunc(months_between(sysdate,hire_date)/12)*12+trunc((months_between(sysdate,hire_date)-(trunc(months_between(sysdate,hire_date)/12))*12))),2) 日
from employees;
--第二种
select employee_id ,trunc(months_between(sysdate,hire_date)/12) 年,trunc((months_between(sysdate,hire_date)-(trunc(months_between(sysdate,hire_date)/12))*12)) 月, 
round(sysdate-(add_months(hire_date,trunc(months_between(sysdate,hire_date)))),2) 日
from employees;
--10找出在任何年份的2月受聘的所有员工
select *
from employees
where to_char(hire_date,'MM')=2;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值