创建部门表
CREATE TABLE department
( DEPARTMENT_ID NUMBER(4) PRIMARY KEY,
DEPARTMENT_NAME VARCHAR2(20) NOT NULL UNIQUE,
ADDRESS VARCHAR2(20) NOT NULL);
INSERT INTO department VALUES(10, 'ACCOUNTING', 'NEW YORK');
INSERT INTO department VALUES(20, 'RESEARCH', 'DALLAS');
INSERT INTO department VALUES(30, 'SALES', 'CHICAGO');
INSERT INTO department VALUES(40, 'IT', 'DALLAS');
INSERT INTO department VALUES(50, 'EXECUTIVE', 'NEW YORK');
INSERT INTO department VALUES(60, 'MARKETING', 'CHICAGO');
COMMIT;
CREATE TABLE employee
( EMPLOYEE_ID NUMBER(4) PRIMARY KEY,
EMPLOYEE_NAME VARCHAR2(20) NOT NULL,
JOB VARCHAR2(50) NOT NULL,
MANAGER_ID NUMBER(4),
HIRE_DATE DATE NOT NULL,
SALARY NUMBER(9, 2) NOT NULL,
COMMISSION NUMBER(9, 2),
DEPARTMENT_ID NUMBER(4) REFERENCES department(DEPARTMENT_ID));
INSERT INTO employee
VALUES(7839, 'KING', 'PRESIDENT', NULL, '20-NOV-01', 5000, NULL, 50);
INSERT INTO employee
VALUES(7596, 'JOST', 'VICE PRESIDENT', 7839, '04-MAY-01', 4500, NULL, 50);
INSERT INTO employee
VALUES(7603, 'CLARK', 'VICE PRESIDENT', 7839, '12-JUN-01', 4000, NULL, 50);
INSERT INTO employee
VALUES(7566, 'JONES', 'PUBLIC ACCOUNTANT', 7596, '05-APR-01', 3000, NULL, 10);
INSERT INTO employee
VALUES(7886, 'STEEL', 'PUBLIC ACCOUNTANT', 7566, '08-MAR-03', 2500, NULL, 10);
INSERT INTO employee
VALUES(7610, 'WILSON', 'ANALYST', 7596, '03-DEC-01', 3000, NULL, 20);
INSERT INTO employee
VALUES(7999, 'WOLFE', 'ANALYST', 7610, '15-FEB-02', 2500, NULL, 20);
INSERT INTO employee
VALUES(7944, 'LEE', 'ANALYST', 7610, '04-SEP-06', 2400, NULL, 20);
INSERT INTO employee
VALUES(7900, 'FISHER', 'SALESMAN', 7603, '06-DEC-01', 3000, 500, 30);
INSERT INTO employee
VALUES(7921, 'JACKSON', 'SALESMAN', 7900, '25-FEB-05', 2500, 400, 30);
INSERT INTO employee
VALUES(7952, 'LANCASTER', 'SALESMAN', 7900, '06-DEC-06', 2000, 150, 30);
INSERT INTO employee
VALUES(7910, 'SMITH', 'DATABASE ADMINISTRATOR', 7596, '20-DEC-01', 2900, NULL, 40);
INSERT INTO employee
VALUES(7788, 'SCOTT', 'PROGRAMMER', 7910, '15-JAN-03', 2500, NULL, 40);
INSERT INTO employee
VALUES(7876, 'ADAMS', 'PROGRAMMER', 7910, '15-JAN-03', 2000, NULL, 40);
INSERT INTO employee
VALUES(7934, 'MILLER','PROGRAMMER', 7876, '25-JAN-02', 1000, NULL, 40);
INSERT INTO employee
VALUES(8000, 'BREWSTER', 'TBA', NULL, '22-AUG-13', 2500, NULL, NULL);
COMMIT;
到目前为止,我已经收到了下面的查询,我无法得到该部门工作的员工人数。我怎么能那么做?
ACCEPT p_1 PROMPT 'Please enter the employee id:'
DECLARE
v_input_emp_id NUMBER := &p_1;
v_emp_name employee.employee_name%TYPE;
v_dept_name department.department_name%TYPE;
v_pay employee.salary%TYPE;
v_n NUMBER;
v_output VARCHAR2(100) := 'The employee id is not in the table';
v_hiredate EMPLOYEE.HIRE_DATE%TYPE;
BEGIN
SELECT COUNT(*)
INTO v_n
FROM employee
WHERE employee_id = v_input_emp_id;
IF v_n = 0 THEN
DBMS_OUTPUT.PUT_LINE(v_input_emp_id || ' is not in the EMPLOYEE table.');
END IF;
IF v_n = 1 THEN
SELECT employee_name, salary + NVL(commission, 0),HIRE_DATE
INTO v_emp_name, v_pay, v_hiredate
FROM employee
WHERE employee_id = v_input_emp_id;
DBMS_OUTPUT.PUT_LINE('USER INPUT:');
DBMS_OUTPUT.PUT_LINE(v_input_emp_id);
DBMS_OUTPUT.PUT_LINE('----------EMPLOYEE----------');
DBMS_OUTPUT.PUT_LINE(rpad('NAME:',10,' ') || lpad(v_emp_name,15));
DBMS_OUTPUT.PUT_LINE(rpad('HIRE DATE:',10) || lpad(v_hiredate,20));
DBMS_OUTPUT.PUT_LINE('TOTAL PAY:' || lpad(TO_CHAR(ROUND(v_pay, 2),
'$9,990.00'),21));
IF v_input_emp_id IS NOT NULL THEN
SELECT manager_id
INTO v_MANAGER_ID
FROM EMPLOYEE
WHERE employee_id = v_input_emp_id;
SELECT employee_name, salary + NVL(commission, 0),HIRE_DATE
INTO v_emp_name, v_pay, v_hiredate
FROM employee
WHERE v_manager_id = employee_id;
DBMS_OUTPUT.PUT_LINE('----------MANAGER----------');
DBMS_OUTPUT.PUT_LINE(rpad('NAME:',10,' ') || lpad(v_emp_name,15));
DBMS_OUTPUT.PUT_LINE(rpad('HIRE DATE:',10) || lpad(v_hiredate,20));
DBMS_OUTPUT.PUT_LINE('TOTAL PAY:' || lpad(TO_CHAR(ROUND(v_pay, 2),
'$9,990.00'),21));
ELSE
DBMS_OUTPUT.PUT_LINE ('NO DATA');
END IF;
IF v_n = 1 THEN
SELECT department_name
INTO v_dept_name
FROM department
INNER JOIN employee
ON department.department_id = employee.department_id
WHERE employee_id = v_input_emp_id;
/*
SELECT department_id
INTO v_dept_id
from department
WHERE department_id = v_dept_id;
SELECT COUNT(*)
INTO v_emp_num
FROM employee INNER JOIN DEPARTMENT
ON DEPARTMENT.DEPARTMENT_ID = EMPLOYEE.DEPARTMENT_ID
WHERE employee.department_id = department.v_dept_id;
*/
DBMS_OUTPUT.PUT_LINE('----------DEPARTMENT----------');
DBMS_OUTPUT.PUT_LINE('NAME: ' || v_dept_name);
/*DBMS_OUTPUT.PUT_LINE('NUMBER OF EMPLOYEES' || ' ' || TO_CHAR(v_emp_num));
*/
ELSE
DBMS_OUTPUT.PUT_LINE('No output!');
END IF;
END IF;
END;
您可能需要简单的Department查询,例如:
SELECT department_name
, count(employee_id) over (partition by department_id) AS count_of_employee
, EMPLOYEE_NAME
, HIRE_DATE
, SALARY + COMMISSION AS pay
, managers.EMPLOYEE_NAME AS manager
, sum(SALARY + COMMISSION) over (partition by department_id) AS total_pay
FROM department
INNER JOIN employee ON department.department_id = employee.department_id
LEFT JOIN employee as managers ON managers.employee_id = employee.MANAGER_ID
WHERE department_id = .........;
或员工:
SELECT department_name
, count_of_employee
, EMPLOYEE_NAME
, HIRE_DATE
, SALARY + COMMISSION AS pay
, managers.EMPLOYEE_NAME AS manager
, total_pay
FROM employee
INNER JOIN department ON department.department_id = employee.department_id
INNER JOIN (
SELECT Count(1) AS count_of_employee
, Sum(SALARY + COMMISSION) AS total_pay
, department_id
FROM employee
GROUP BY department_id
) AS employee_total ON employee_total.department_id = employee.department_id
LEFT JOIN employee as managers ON managers.employee_id = employee.MANAGER_ID
WHERE employee_id = v_input_emp_id;
问题内容: 我试图找出一个查询,该查询显示在多个部门中工作的员工 人数 (数量)。这里的表名和字段: (id_employee,employee_name,薪水) (id_dept,dept_name,预算) (id_employee,id_dept,workhours_percentage) 假设Department_Employee表的内容是 进行正确的查询后,结果应为2(员工),因为有2个员
问题内容: 我想显示带有的以及,并且计数应大于5,并且我想让一月份没有被雇用的员工。 我尝试了以下查询 但是在这里我没有数。我也想数。 问题答案: 该查询返回department_id,并且由于我按department_id分组,因此将返回属于每个部门的员工数 输出看起来像这样
我有两个表,分别名为和。 员工(Emp_ID、姓名、职位、DeptID) 示例输出:
我希望通过Workday API检索Workday worker(又名employee)的web配置文件URL。使用案例是,我正在构建一个聊天机器人来检索用户信息,我希望能够深入链接到工人(员工)的web配置文件。 问题是我不能做以下任何一项: 从API获取web配置文件URL 从API中的数据创建web配置文件URL web配置文件URL如下所示。用户ID看起来像就在扩展名,因为这是员工档案之间
请考虑两个表-员工和部门
我试图用一个服务人员使用Workbox制作一个非常基本的PWA,但是我有一个问题。我正在使用命令行界面来生成服务工作人员,一切正常,完美的亮点,但我不能将我的index.html添加到运行时缓存中。我必须将其添加到全局模式,以便我的网站在离线模式下工作,但当我更新index.html文件时,除非我清除缓存,否则不会更新。我想要和我的js和css一样的东西。当我升级这些文件时,它们会更新。这是我的工