問題ID : 13715について
riverisland
投稿数: 2
EMPLOYEES表の中から『部署が「営業」で、10年以内に入社した給与が30万円以上の従業員を出力します。』という問題の答えが下記のSQL文だったので、検証用のテーブルを作成して実行したのですが実行結果が何も表示されません。
//正解SQL文//
SELECT department_id, employee_name, hiredate, salary FROM employees
WHERE hiredate > SYSDATE - 365 * 10
INTERSECT
SELECT department_id, employee_name, hiredate, salary FROM employees
WHERE salary >= 300000
MINUS
SELECT department_id, employee_name, hiredate, salary FROM employees
WHERE department_id NOT IN (SELECT department_id FROM departments WHERE department_name = '営業')
//実行結果//
DEPARTMENT_ID|EMPLOYEE_NAME|HIREDATE|SALARY|
-------------|-------------|--------|------|
最初はA5M2とDBeaverというクライアントソフトで実行しましたが何も表示されなかったので、コマンドプロンプトで実行してもダメでした。
ほかの選択肢のSQL文だと下記のSQL文も違う結果でした。
//検証SQL文//
SELECT department_id, employee_name, hiredate, salary FROM employees
WHERE department_id = (SELECT department_id FROM departments WHERE department_name = '営業')
UNION
SELECT department_id, employee_name, hiredate, salary FROM employees
WHERE hiredate > SYSDATE - 365 * 10
INTERSECT
SELECT department_id, employee_name, hiredate, salary FROM employees
WHERE salary >= 300000
//実行結果//
DEPARTMENT_ID|EMPLOYEE_NAME|HIREDATE |SALARY|
-------------|-------------|-------------------|------|
2|伊藤佳奈 |2010-04-01 00:00:00|300000|
2|佐藤昭夫 |2001-04-01 00:00:00|500000|
2|星野健一 |2005-10-01 00:00:00|400000|
※解説では7件のデータが選択されていた
何かご見解いただけるとありがたいです。
//テーブル作成SQL//
CREATE TABLE employees
(employee_id NUMBER(4) CONSTRAINT pk_emp PRIMARY KEY,
employee_name VARCHAR2(10),
yomi VARCHAR2(20),
job_id NUMBER(4),
manager_id NUMBER(4),
hiredate DATE,
salary NUMBER(7),
commission NUMBER(7),
department_id NUMBER(2) CONSTRAINT fk_deptno REFERENCES departments(department_id));
INSERT INTO employees VALUES (1001, '山田二郎', 'やまだじろう', 1002, NULL, '2001-04-01', 500000, 2000000, 1);
INSERT INTO employees VALUES (1002, '佐藤昭夫', 'さとうあきお', 1002, NULL, '2001-04-01', 500000, 2000000, 2);
INSERT INTO employees VALUES (1003, '山口洋子', 'やまぐちようこ', 1002, NULL, '2001-10-01', 500000, 2000000, 3);
INSERT INTO employees VALUES (1004, '田中浩介', 'たなかこうすけ', 1002, NULL, '2001-10-01', 500000, 2000000, 4);
INSERT INTO employees VALUES (1005, '加藤昭彦', 'かとうあきひこ', 1002, NULL, '2001-10-01', 500000, 2000000, 5);
INSERT INTO employees VALUES (1006, '佐々木明子', 'ささきあきこ', 1001, NULL, '2001-04-01', 800000, 5000000, 1);
INSERT INTO employees VALUES (1007, '菊池浩二', 'きくちこうじ', 1001, NULL, '2001-04-01', 800000, 5000000, 1);
INSERT INTO employees VALUES (1008, '中山大輔', 'なかやまだいすけ', 1003, 1001, '2003-04-01', 400000, 1500000, 1);
INSERT INTO employees VALUES (1009, '星野健一', 'ほしのけんいち', 1005, 1002,'2005-10-01', 400000, 1500000, 2);
INSERT INTO employees VALUES (1010, '斎藤京子', 'さいとうきょうこ', 1006, 1003, '2002-12-01', 400000, 1200000, 3);
INSERT INTO employees VALUES (1011, '吉田亜希', 'よしだあき', 1007, 1004, '2007-04-01', 400000, 1000000, 4);
INSERT INTO employees VALUES (1012, '阿部伊吹', 'あべいぶき', 1008, 1005, '2010-04-01', 400000, 800000, 5);
INSERT INTO employees VALUES (1013, '米村真司', 'よねむらしんじ', 1004, 1001, '2011-04-01', 350000, 800000, 1);
INSERT INTO employees VALUES (1014, '伊藤佳奈', 'いとうかな', 1005, 1002, '2010-04-01', 300000, 800000, 2);
INSERT INTO employees VALUES (1015, '橋本淳', 'はしもとあつし', 1006, 1003, '2009-12-01', 300000, 800000, 3);
INSERT INTO employees VALUES (1016, '井上悦子', 'いのうええつこ', 1007, 1004, '2010-04-01', 200000, 800000, 4);
INSERT INTO employees VALUES (1017, '渡辺和也', 'わたなべかずや', 1008, 1005, '2012-04-01', NULL, NULL, 5);
INSERT INTO employees VALUES (1018, '塚本孝', 'つかもとたかし', 1003, 1001, '2012-04-01', NULL, NULL, 1);
INSERT INTO employees VALUES (1019, '野口圭子', 'のぐちけいこ', 1004, 1001, '2012-04-01', NULL, NULL, 1);
INSERT INTO employees VALUES (1020, '内田雄介', NULL, 1004, 1001, '2012-04-01', 200000, NULL, 1);
INSERT INTO employees VALUES (1021, '高田明', NULL, 1004, 1001, '2012-04-01', 200000, NULL, 1);
INSERT INTO employees VALUES (1022, '坂本真', NULL, 1004, 1001, '2012-04-01', 200000, NULL, 1);
//正解SQL文//
SELECT department_id, employee_name, hiredate, salary FROM employees
WHERE hiredate > SYSDATE - 365 * 10
INTERSECT
SELECT department_id, employee_name, hiredate, salary FROM employees
WHERE salary >= 300000
MINUS
SELECT department_id, employee_name, hiredate, salary FROM employees
WHERE department_id NOT IN (SELECT department_id FROM departments WHERE department_name = '営業')
//実行結果//
DEPARTMENT_ID|EMPLOYEE_NAME|HIREDATE|SALARY|
-------------|-------------|--------|------|
最初はA5M2とDBeaverというクライアントソフトで実行しましたが何も表示されなかったので、コマンドプロンプトで実行してもダメでした。
ほかの選択肢のSQL文だと下記のSQL文も違う結果でした。
//検証SQL文//
SELECT department_id, employee_name, hiredate, salary FROM employees
WHERE department_id = (SELECT department_id FROM departments WHERE department_name = '営業')
UNION
SELECT department_id, employee_name, hiredate, salary FROM employees
WHERE hiredate > SYSDATE - 365 * 10
INTERSECT
SELECT department_id, employee_name, hiredate, salary FROM employees
WHERE salary >= 300000
//実行結果//
DEPARTMENT_ID|EMPLOYEE_NAME|HIREDATE |SALARY|
-------------|-------------|-------------------|------|
2|伊藤佳奈 |2010-04-01 00:00:00|300000|
2|佐藤昭夫 |2001-04-01 00:00:00|500000|
2|星野健一 |2005-10-01 00:00:00|400000|
※解説では7件のデータが選択されていた
何かご見解いただけるとありがたいです。
//テーブル作成SQL//
CREATE TABLE employees
(employee_id NUMBER(4) CONSTRAINT pk_emp PRIMARY KEY,
employee_name VARCHAR2(10),
yomi VARCHAR2(20),
job_id NUMBER(4),
manager_id NUMBER(4),
hiredate DATE,
salary NUMBER(7),
commission NUMBER(7),
department_id NUMBER(2) CONSTRAINT fk_deptno REFERENCES departments(department_id));
INSERT INTO employees VALUES (1001, '山田二郎', 'やまだじろう', 1002, NULL, '2001-04-01', 500000, 2000000, 1);
INSERT INTO employees VALUES (1002, '佐藤昭夫', 'さとうあきお', 1002, NULL, '2001-04-01', 500000, 2000000, 2);
INSERT INTO employees VALUES (1003, '山口洋子', 'やまぐちようこ', 1002, NULL, '2001-10-01', 500000, 2000000, 3);
INSERT INTO employees VALUES (1004, '田中浩介', 'たなかこうすけ', 1002, NULL, '2001-10-01', 500000, 2000000, 4);
INSERT INTO employees VALUES (1005, '加藤昭彦', 'かとうあきひこ', 1002, NULL, '2001-10-01', 500000, 2000000, 5);
INSERT INTO employees VALUES (1006, '佐々木明子', 'ささきあきこ', 1001, NULL, '2001-04-01', 800000, 5000000, 1);
INSERT INTO employees VALUES (1007, '菊池浩二', 'きくちこうじ', 1001, NULL, '2001-04-01', 800000, 5000000, 1);
INSERT INTO employees VALUES (1008, '中山大輔', 'なかやまだいすけ', 1003, 1001, '2003-04-01', 400000, 1500000, 1);
INSERT INTO employees VALUES (1009, '星野健一', 'ほしのけんいち', 1005, 1002,'2005-10-01', 400000, 1500000, 2);
INSERT INTO employees VALUES (1010, '斎藤京子', 'さいとうきょうこ', 1006, 1003, '2002-12-01', 400000, 1200000, 3);
INSERT INTO employees VALUES (1011, '吉田亜希', 'よしだあき', 1007, 1004, '2007-04-01', 400000, 1000000, 4);
INSERT INTO employees VALUES (1012, '阿部伊吹', 'あべいぶき', 1008, 1005, '2010-04-01', 400000, 800000, 5);
INSERT INTO employees VALUES (1013, '米村真司', 'よねむらしんじ', 1004, 1001, '2011-04-01', 350000, 800000, 1);
INSERT INTO employees VALUES (1014, '伊藤佳奈', 'いとうかな', 1005, 1002, '2010-04-01', 300000, 800000, 2);
INSERT INTO employees VALUES (1015, '橋本淳', 'はしもとあつし', 1006, 1003, '2009-12-01', 300000, 800000, 3);
INSERT INTO employees VALUES (1016, '井上悦子', 'いのうええつこ', 1007, 1004, '2010-04-01', 200000, 800000, 4);
INSERT INTO employees VALUES (1017, '渡辺和也', 'わたなべかずや', 1008, 1005, '2012-04-01', NULL, NULL, 5);
INSERT INTO employees VALUES (1018, '塚本孝', 'つかもとたかし', 1003, 1001, '2012-04-01', NULL, NULL, 1);
INSERT INTO employees VALUES (1019, '野口圭子', 'のぐちけいこ', 1004, 1001, '2012-04-01', NULL, NULL, 1);
INSERT INTO employees VALUES (1020, '内田雄介', NULL, 1004, 1001, '2012-04-01', 200000, NULL, 1);
INSERT INTO employees VALUES (1021, '高田明', NULL, 1004, 1001, '2012-04-01', 200000, NULL, 1);
INSERT INTO employees VALUES (1022, '坂本真', NULL, 1004, 1001, '2012-04-01', 200000, NULL, 1);
投稿ツリー
-
問題ID : 13715について
(riverisland, 2021-4-13 14:48)
-
Re: 問題ID : 13715について
(arashi1977, 2021-4-13 15:08)
- Re: 問題ID : 13715について (riverisland, 2021-4-13 15:39)
-
Re: 問題ID : 13715について
(arashi1977, 2021-4-13 15:08)