0
点赞
收藏
分享

微信扫一扫

xxx公司的sql面试

ZMXQQ233 2022-01-24 阅读 19

Table EMPLOYEES Structure:

EMPLOYEE_ID      NUMBER        Primary Key,

FIRST_NAME       VARCHAR2(25),

LAST_NAME       VARCHAR2(25),

Salary number(8,2),

HiredDate DATE,

Departmentid number(2)

Table Departments Structure:

Departmentid number(2)        Primary Key,

DepartmentName  VARCHAR2(25)

 (2)基于上述EMPLOYEES表写出查询:写出雇用日期在今年的,或者工资在[1000,2000]之间的,或者员工姓名(last_name)以’Obama’打头的所有员工,列出这些员工的全部个人信息。(4分)

Mysql:

select * from employees

where Year(hiredDate) = Year(date())

or (salary between 1000 and 200)

or left(last_name,3)='abc';

Oracle:

select * from emp

where to_char(hiredate,'yyyy') = to_char(sysdate,'yyyy')

or (sal between 1000 and 2000)

or substr(ename,1,3)='ALL';

  1. 基于上述EMPLOYEES表写出查询:查出部门平均工资大于1800元的部门的所有员工,列出这些员工的全部个人信息。(4分)

select id,name,salary,deptid did from employee1 where (select avg(salary)

 from employee1 where deptid = did) > 1800;

Oracle:

select * from emp where deptno in

(select deptno from emp  group by deptno having avg(sal)>1800);

(4) 基于上述EMPLOYEES表写出查询:查出个人工资高于其所在部门平均工资的员工,列出这些员工的全部个人信息及该员工工资高出部门平均工资百分比。(5分)

select employee1.*,(employee1.salary-t.avgSalary)*100/employee1.salary

from employee1,

(select deptid,avg(salary) avgSalary from employee1 group by deptid) as t

where employee1.deptid = t.deptid and employee1.salary>t.avgSalary;

Oracle:

select emp1.*,emp2.avgSal,

trunc((emp1.sal-emp2.avgSal)/emp2.avgSal*100,0)||'%'  highSal

from emp emp1,(select deptno,avg(sal) avgSal from emp  group by deptno) emp2

where emp1.deptno=emp2.deptno and emp1.sal>emp2.avgSal;

举报

相关推荐

0 条评论