oracle习题

如果错误或者更加优秀的解决方法,欢迎各位大大指教,共同进步,共创和谐社会,哈哈。

emmmmm,本人有点小懒可能不会及时更新或回复,一切随缘吧。

/*
1.查询雇佣时间在1997年之后的员工信息。
*/

select * from employees where to_char(hire_date, ‘yyyy’) > 1997;

/*
2.查询有提成的员工信息(last name, job, salary, and commission),并按工资降序排列
*/

select last_name,job_id,salary,commission_pct
from employees
where commission_pct is not null
order by salary desc;
/*
3.Show the employees that have no commission with a 10% raise in their salary (round off thesalaries).
*/

select ‘the salary of ’ || last_name || ’ after a 10% raise is ’ ||
salary * 1.1 as new_salary
from employees
where commission_pct is null;

/*
4.Show the last names of all employees together with the number of years and the number of completed months that they have been employed.
*/

select last_name,
trunc(months_between(sysdate, hire_date) / 12, 0) as years,
mod((to_char(hire_date, ‘mm’) - to_char(sysdate, ‘mm’) + 12), 12) as months
from employees;

/*
5.Show those employees that have a name starting with J, K, L, or M.
*/

select last_name
from empLoyees
where substr(last_name, 1, 1) IN (‘J’, ‘K’, ‘L’, ‘M’);

/*
6.Show all employees, and indicate with “Yes” or “No” whether they receive a commission.
*/

select last_name,salary,nvl2(commission_pct,’Yes’,’No’)
from employees;

/*
7.Show the department names, locations, names, job titles, and salaries of employees who work in location 1800.
*/

select department_name,location_id,last_name,jobs.job_id,salary
from departments dept,jobs,employees
where dept.department_id=employees.department_id
and employees.job_id = jobs.job_id
and location_id = 1800;
/*
8.How many employees have a name that ends with an n? Create two possible solutions.
*/

select count(*) from employees where substr(last_name, -1) = ‘n’


select count(*) from employees where last_name like ‘%n’;

/*
9.Show the names and locations for all departments, and the number of employees working in each department. Make sure that departments without employees are included as well.
*/

select d.department_id, department_name, location_id, nvl(counts, 0)
from departments d,
(select count(employee_id) as counts, department_id
from employees
group by department_id) e
where e.department_id(+) = d.department_id;

/*
10.Which jobs are found in departments 10 and 20?
*/

select distinct job_id from employees where department_id between 10 and 20;

/*
11.Which jobs are found in the Administration and Executive departments, and how many employees do these jobs? Show the job with the highest frequency first.
*/

select job_id, count(*) as fruquency
from (select *
from employees
where department_id in
(select department_id
from d

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值