本文介绍了Sql Case语句问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请有人帮助我这两个问题

1.使用CASE语句根据以下条件显示员工水平.
按管理级别订购结果.

(i)如果员工未由任何人管理,则他们的管理级别应为高级主管".

(ii)如果一名员工管理其他员工,则他们的管理级别应为中级管理".

提示:使用子查询查找中层经理

(iii)其余员工的管理级别应为职员"

EMPNO ENAME MANAGEMENT_LEVEL
----- ---------- ----------------
7566 JONES中层管理人员
7698 BLAKE中层管理人员
7782 CLARK中层管理人员
7902 FORD中层管理人员
7788 SCOTT中层管理人员
7839 KING高级主管
7369 SMITH工作人员
7499 ALLEN员工
7521 WARD职员
7876 ADAMS员工
7844特纳员工
7654 MARTIN员工
7900 JAMES员工
7934 MILLER员工


2.重复问题1中的查询,但颠倒前两个测试的顺序,并观察KING输出的差异.为什么会发生这种情况?

EMPNO ENAME MANAGEMENT_LEVEL
----- ---------- -----------------
7698 BLAKE中层管理人员
7782 CLARK中层管理人员
7788 SCOTT中层管理人员
7902 FORD中层管理人员
7566 JONES中层管理人员
7839 KING中层管理人员
7654 MARTIN员工
7499 ALLEN员工
7521 WARD职员
7369 SMITH工作人员
7844特纳员工
7876 ADAMS员工
7934 MILLER员工
7900 JAMES Staff

Please any one help me those two questions

1.Use a CASE statement to show levels of employees according to the following criteria.
Order the results by management level.

(i)If the employee is not managed by anyone, they should have a Management Level of ‘Senior executive’.

(ii) If an employee manages other staff they should have a Management Level of ‘Middle Management’.

Hint : Use a subquery to find the middle managers

(iii)Remaining employees should have a Management Level of ‘Staff’

EMPNO ENAME MANAGEMENT_LEVEL
----- ---------- ----------------
7566 JONES Middle management
7698 BLAKE Middle management
7782 CLARK Middle management
7902 FORD Middle management
7788 SCOTT Middle management
7839 KING Senior executive
7369 SMITH Staff
7499 ALLEN Staff
7521 WARD Staff
7876 ADAMS Staff
7844 TURNER Staff
7654 MARTIN Staff
7900 JAMES Staff
7934 MILLER Staff


2.Repeat the query in Question 1 but reverse the sequence of the first two tests and observe the difference in the output for KING. Why does this occur?

EMPNO ENAME MANAGEMENT_LEVEL
----- ---------- -----------------
7698 BLAKE Middle management
7782 CLARK Middle management
7788 SCOTT Middle management
7902 FORD Middle management
7566 JONES Middle management
7839 KING Middle management
7654 MARTIN Staff
7499 ALLEN Staff
7521 WARD Staff
7369 SMITH Staff
7844 TURNER Staff
7876 ADAMS Staff
7934 MILLER Staff
7900 JAMES Staff

推荐答案


这篇关于Sql Case语句问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 09:48