/*-------10、哪些员工跟William(FIRST_NAME)、Smith(LAST_NAME)做不一样的职位。--------*/
SQL> SELECT FIRST_NAME || ' ' || LAST_NAME FROM HR.EMPLOYEES
2 WHERE JOB_ID <> (SELECT DISTINCT JOB_ID FROM EMPLOYEES
3 WHERE FIRST_NAME = 'William' AND LAST_NAME = 'Smith');
FIRST_NAME||''||LAST_NAME
----------------------------------------------
Steven King
Neena Kochhar
Lex De Haan
Alexander Hunold
----...初始有77条数据
/*--------11、显示有提成的员工的信息:名字、提成、所在部门名称、所在地区的名称。---------*/
SQL> SELECT E.FIRST_NAME || ' ' || E.LAST_NAME AS NAME,
2 E.COMMISSION_PCT,D.DEPARTMENT_NAME,L.CITY
3 FROM HR.EMPLOYEES E,HR.DEPARTMENTS D,HR.LOCATIONS L
4 WHERE E.DEPARTMENT_ID = D.DEPARTMENT_ID
5 AND D.LOCATION_ID = L.LOCATION_ID
6 AND E.COMMISSION_PCT IS NOT NULL;
/*--------12、显示Executive部门有哪些职位。---------*/
SQL> SELECT DISTINCT E.JOB_ID FROM HR.EMPLOYEES E,HR.DEPARTMENTS D
2 WHERE D.DEPARTMENT_ID = E.DEPARTMENT_ID
3 AND D.DEPARTMENT_NAME = 'Executive';
JOB_ID
----------
AD_PRES
AD_VP
/*--------13、整个公司中,最高工资和最低工资相差多少。---------*/
SQL> SELECT MAX(SALARY) - MIN(SALARY) FROM HR.EMPLOYEES;
MAX(SALARY)-MIN(SALARY)
-----------------------
21900
/*--------14、提成大于0 的人数。---------*/
SQL> SELECT COUNT(*) AS 提成大小0的人数 FROM HR.EMPLOYEES
2 WHERE COMMISSION_PCT > 0;
提成大小0的人数
---------------
35
--或者
SQL> SELECT COUNT(COMMISSION_PCT) AS 提成大小0的人数
2 FROM HR.EMPLOYEES
3 WHERE COMMISSION_PCT > 0;
提成大小0的人数
---------------
35
/*--------15、显示整个公司的最高工资、最低工资、工资总和、平均工资保留到整数位。---------*/
SQL> SELECT MAX(NVL(SALARY,0)) AS 最高工资,
2 MIN(NVL(SALARY,0)) AS 最低工资,
3 SUM(NVL(SALARY,0)) AS 工资总和,
4 ROUND(AVG(NVL(SALARY,0))) AS 平均工资
5 FROM HR.EMPLOYEES;
最高工资 最低工资 工资总和 平均工资
---------- ---------- ---------- ---------
24000 2100 698011 6523
/*--------16、整个公司有多少个领导。---------*/
SQL> SELECT COUNT(DISTINCT(MANAGER_ID)) FROM HR.EMPLOYEES
2 WHERE MANAGER_ID IS NOT NULL;
COUNT(DISTINCT(MANAGER_ID))
---------------------------
18
SQL> SELECT FIRST_NAME || ' ' || LAST_NAME FROM HR.EMPLOYEES
2 WHERE JOB_ID <> (SELECT DISTINCT JOB_ID FROM EMPLOYEES
3 WHERE FIRST_NAME = 'William' AND LAST_NAME = 'Smith');
FIRST_NAME||''||LAST_NAME
----------------------------------------------
Steven King
Neena Kochhar
Lex De Haan
Alexander Hunold
----...初始有77条数据
/*--------11、显示有提成的员工的信息:名字、提成、所在部门名称、所在地区的名称。---------*/
SQL> SELECT E.FIRST_NAME || ' ' || E.LAST_NAME AS NAME,
2 E.COMMISSION_PCT,D.DEPARTMENT_NAME,L.CITY
3 FROM HR.EMPLOYEES E,HR.DEPARTMENTS D,HR.LOCATIONS L
4 WHERE E.DEPARTMENT_ID = D.DEPARTMENT_ID
5 AND D.LOCATION_ID = L.LOCATION_ID
6 AND E.COMMISSION_PCT IS NOT NULL;
/*--------12、显示Executive部门有哪些职位。---------*/
SQL> SELECT DISTINCT E.JOB_ID FROM HR.EMPLOYEES E,HR.DEPARTMENTS D
2 WHERE D.DEPARTMENT_ID = E.DEPARTMENT_ID
3 AND D.DEPARTMENT_NAME = 'Executive';
JOB_ID
----------
AD_PRES
AD_VP
/*--------13、整个公司中,最高工资和最低工资相差多少。---------*/
SQL> SELECT MAX(SALARY) - MIN(SALARY) FROM HR.EMPLOYEES;
MAX(SALARY)-MIN(SALARY)
-----------------------
21900
/*--------14、提成大于0 的人数。---------*/
SQL> SELECT COUNT(*) AS 提成大小0的人数 FROM HR.EMPLOYEES
2 WHERE COMMISSION_PCT > 0;
提成大小0的人数
---------------
35
--或者
SQL> SELECT COUNT(COMMISSION_PCT) AS 提成大小0的人数
2 FROM HR.EMPLOYEES
3 WHERE COMMISSION_PCT > 0;
提成大小0的人数
---------------
35
/*--------15、显示整个公司的最高工资、最低工资、工资总和、平均工资保留到整数位。---------*/
SQL> SELECT MAX(NVL(SALARY,0)) AS 最高工资,
2 MIN(NVL(SALARY,0)) AS 最低工资,
3 SUM(NVL(SALARY,0)) AS 工资总和,
4 ROUND(AVG(NVL(SALARY,0))) AS 平均工资
5 FROM HR.EMPLOYEES;
最高工资 最低工资 工资总和 平均工资
---------- ---------- ---------- ---------
24000 2100 698011 6523
/*--------16、整个公司有多少个领导。---------*/
SQL> SELECT COUNT(DISTINCT(MANAGER_ID)) FROM HR.EMPLOYEES
2 WHERE MANAGER_ID IS NOT NULL;
COUNT(DISTINCT(MANAGER_ID))
---------------------------
18