您好,欢迎访问一九零五行业门户网

SQL笔试题:公司员工与部门查询

建表: departments:department_id(primary key),department_name,locationemployees:employee_id(primary key),employee_name,employee_job,manager,salary,department_id 列出employees表中各部门的部门号,最高工资,最低工资 select max(salary) as 最高
建表:
departments:department_id(primary key),department_name,locationemployees:employee_id(primary key),employee_name,employee_job,manager,salary,department_id
列出employees表中各部门的部门号,最高工资,最低工资 select max(salary) as 最高工资,min(salary) as 最低工资,department_id from employees group by department_id;
列出employees表中各部门employee_job为'clerk'的员工的最低工资,最高工资 select max(salary) as 最高工资,min(salary) as 最低工资,department_id as 部门号 from employees where employee_job = 'clerk' group by department_id;
对于employees中最低工资小于1000的部门,列出employee_job为'clerk'的员工的部门号,最低工资,最高工资 select max(salary) as 最高工资,min(salary) as 最低工资,department_id as 部门号 from employees as bwhere employee_job ='clerk' and 1000>(select min(salary) from employees as a where a.department_id = b.department_id) group by b.department_id
根据部门号由高而低,工资有低而高列出每个员工的姓名,部门号,工资 select department_id as 部门号,employee_name as 姓名,salary as 工资 from employees order by department_id desc,salary asc
写出对上题的另一解决方法 还没想到,如果你又答案,请联系www.nowamagic.net,我的联系方式在网站首页。
列出'张三'所在部门中每个员工的姓名与部门号 select employee_name,department_id from employees where department_id = (select department_id from employees where employee_name = '张三')
列出每个员工的姓名,工作,部门号,部门名 select employee_name,employee_job,employees.department_id,departments.department_name from employees,departments where employees.department_id = departments.department_id
列出employees中工作为'clerk'的员工的姓名,工作,部门号,部门名 select employee_name,employee_job,departments.department_id,department_name from employees,departments where departments.department_id = employees.department_id and department_job = 'clerk'
对于employees中有管理者的员工,列出姓名,管理者姓名(管理者外键为manager) select a.employee_name as 姓名,b.employee_name as 管理者 from employees as a,employees as b where a.manager is not null and a.manager = b.employee_id
对于departments表中,列出所有部门名,部门号,同时列出各部门工作为'clerk'的员工名与工作 select department_name as 部门名,departments.department_id as 部门号,employee_name as 员工名,employee_job as 工作 from departments,employees where departments.department_id *= employees.department_id and employee_job = 'clerk'
对于工资高于本部门平均水平的员工,列出部门号,姓名,工资,按部门号排序 select a.department_id as 部门号,a.employee_name as 姓名,a.salary as 工资 from employees as awhere a.salary>(select avg(salary) from employees as b where a.department_id = b.department_id) order by a.department_id
对于employees,列出各个部门中平均工资高于本部门平均水平的员工数和部门号,按部门号排序 select count(a.salary) as 员工数,a.department_id as 部门号 from employees as awhere a.salary>(select avg(salary) from employees as b where a.department_id = b.department_id) group by a.department_id order by a.department_id
对于employees中工资高于本部门平均水平,人数多与1人的,列出部门号,人数,按部门号排序 select count(a.employee_id) as 员工数,a.department_id as 部门号,avg(salary) as 平均工资 from employees as awhere (select count(c.employee_id) from employees as c where c.department_id = a.department_id and c.salary>(select avg(salary) from employees as b where c.department_id = b.department_id))>1group by a.department_id order by a.department_id
对于employees中低于自己工资至少5人的员工,列出其部门号,姓名,工资,以及工资少于自己的人数 select a.department_id,a.employee_name,a.salary,(select count(b.employee_name) from employees as b where b.salary < a.salary) as 人数 from employees as awhere (select count(b.employee_name) from employees as b where b.salary5
其它类似信息

推荐信息