Oracle-11:联合查询


------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥-------------

联合查询的实际上的意义就是从俩个结果集中拿有特定联系的结果封装为一个结果集

数据库脚本给放一份,供测试使用

create table DEPT
(
  deptno NUMBER(2) not null,
  dname  VARCHAR2(20),
  loc    VARCHAR2(13)
);

alter table DEPT
  add constraint PK_DEPT primary key (DEPTNO);

create table TEACHER
(
  tno       NUMBER(4) not null,
  tname     VARCHAR2(30) not null,
  tid       CHAR(18),
  gendar    CHAR(3),
  birthdate DATE,
  job       VARCHAR2(20),
  hiredate  DATE,
  sal       NUMBER(7,2),
  deptno    NUMBER(2),
  mgrno     NUMBER(4),
  comm      NUMBER(7,2)
);

insert into DEPT (deptno, dname, loc)
values (40, ‘人力部‘, ‘北京海淀‘);
insert into DEPT (deptno, dname, loc)
values (30, ‘产品部‘, ‘北京海淀‘);
insert into DEPT (deptno, dname, loc)
values (20, ‘招生部‘, ‘上海虹桥‘);
insert into DEPT (deptno, dname, loc)
values (10, ‘研究院‘, ‘北京海淀‘);
insert into DEPT (deptno, dname, loc)
values (50, ‘系统部‘, ‘北京昌平‘);
commit;

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1002, ‘赵辉‘, ‘110101760609001   ‘, ‘男‘, to_date(‘09-06-1976‘, ‘dd-mm-yyyy‘), ‘考试专员‘, to_date(‘23-05-2006 02:40:40‘, ‘dd-mm-yyyy hh24:mi:ss‘), 29370.95, 40, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1003, ‘杨利乐‘, ‘110101198705256045‘, ‘女‘, to_date(‘25-05-1987‘, ‘dd-mm-yyyy‘), ‘考试专员‘, to_date(‘24-11-2011 16:08:38‘, ‘dd-mm-yyyy hh24:mi:ss‘), 7134.32, 40, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1004, ‘王益辉‘, ‘110101199108154770‘, ‘男‘, to_date(‘15-08-1991‘, ‘dd-mm-yyyy‘), ‘营销专员‘, to_date(‘16-01-2012 03:12:43‘, ‘dd-mm-yyyy hh24:mi:ss‘), 30737.36, 20, null, 2300.00);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1006, ‘秦璐璐‘, ‘110101199004153068‘, ‘女‘, to_date(‘14-04-1990‘, ‘dd-mm-yyyy‘), ‘运维工程师‘, to_date(‘20-06-2012 00:47:09‘, ‘dd-mm-yyyy hh24:mi:ss‘), 9013.25, 10, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1007, ‘梁改焕‘, ‘110101196911206548‘, ‘女‘, to_date(‘20-11-1969‘, ‘dd-mm-yyyy‘), ‘讲师‘, to_date(‘13-06-2006 23:07:02‘, ‘dd-mm-yyyy hh24:mi:ss‘), 8664.16, 50, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1008, ‘冯爱仙‘, ‘110101196804021521‘, ‘女‘, to_date(‘02-04-1968‘, ‘dd-mm-yyyy‘), ‘讲师‘, to_date(‘06-06-2006 13:41:50‘, ‘dd-mm-yyyy hh24:mi:ss‘), 29936.29, 30, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1009, ‘秦亚杰‘, ‘110101196312163531‘, ‘男‘, to_date(‘16-12-1963‘, ‘dd-mm-yyyy‘), ‘岗位分析师‘, to_date(‘13-07-2005 06:32:30‘, ‘dd-mm-yyyy hh24:mi:ss‘), 24991.44, 30, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1010, ‘刘浩星‘, ‘110101198806283516‘, ‘男‘, to_date(‘28-06-1988‘, ‘dd-mm-yyyy‘), ‘考试专员‘, to_date(‘24-11-2011 16:08:38‘, ‘dd-mm-yyyy hh24:mi:ss‘), 22645.92, null, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1011, ‘秦春叶‘, ‘110101197103033540‘, ‘女‘, to_date(‘03-03-1971‘, ‘dd-mm-yyyy‘), ‘网络营销师‘, to_date(‘07-07-2007 16:02:04‘, ‘dd-mm-yyyy hh24:mi:ss‘), 31653.23, 50, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1012, ‘陈水花‘, ‘110101192811043026‘, ‘女‘, to_date(‘04-11-1928‘, ‘dd-mm-yyyy‘), ‘考试专员‘, to_date(‘29-01-2005 23:21:59‘, ‘dd-mm-yyyy hh24:mi:ss‘), 29773.37, 20, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1013, ‘马付妮‘, ‘110101195806133522‘, ‘女‘, to_date(‘13-06-1958‘, ‘dd-mm-yyyy‘), ‘研发‘, to_date(‘17-11-2004 08:54:04‘, ‘dd-mm-yyyy hh24:mi:ss‘), 17041.60, 40, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1015, ‘刘得安‘, ‘110101195210083518‘, ‘男‘, to_date(‘08-10-1952‘, ‘dd-mm-yyyy‘), ‘考试专员‘, to_date(‘13-03-2005 23:25:37‘, ‘dd-mm-yyyy hh24:mi:ss‘), 30356.99, 20, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1016, ‘高利芹‘, ‘110101198307276020‘, ‘女‘, to_date(‘27-07-1983‘, ‘dd-mm-yyyy‘), ‘岗位分析师‘, to_date(‘24-11-2011 16:08:38‘, ‘dd-mm-yyyy hh24:mi:ss‘), 25751.36, null, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1017, ‘刘志刚‘, ‘110101197806164493‘, ‘男‘, to_date(‘16-06-1978‘, ‘dd-mm-yyyy‘), ‘运维工程师‘, to_date(‘10-05-2008 13:46:33‘, ‘dd-mm-yyyy hh24:mi:ss‘), 22344.73, 20, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1018, ‘高心立‘, ‘110101194102076011‘, ‘男‘, to_date(‘07-02-1941‘, ‘dd-mm-yyyy‘), ‘网络营销师‘, to_date(‘03-03-2005 15:17:07‘, ‘dd-mm-yyyy hh24:mi:ss‘), 19981.02, 40, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1019, ‘徐丽‘, ‘11010119790809354X‘, ‘男‘, to_date(‘09-08-1979‘, ‘dd-mm-yyyy‘), ‘研发‘, to_date(‘09-12-2009 18:37:22‘, ‘dd-mm-yyyy hh24:mi:ss‘), 10950.33, 30, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1021, ‘刘志红‘, ‘110101196504284452‘, ‘男‘, to_date(‘28-04-1965‘, ‘dd-mm-yyyy‘), ‘岗位分析师‘, to_date(‘20-09-2011 10:51:33‘, ‘dd-mm-yyyy hh24:mi:ss‘), 7122.60, 20, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1022, ‘孔鹏飞‘, ‘110101198603304014‘, ‘男‘, to_date(‘30-03-1986‘, ‘dd-mm-yyyy‘), ‘人力资源师‘, to_date(‘24-11-2011 16:08:38‘, ‘dd-mm-yyyy hh24:mi:ss‘), 7045.28, 40, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1023, ‘李建坡‘, ‘110101731107301   ‘, ‘男‘, to_date(‘07-11-1973‘, ‘dd-mm-yyyy‘), ‘网络营销师‘, to_date(‘04-07-2009 06:28:20‘, ‘dd-mm-yyyy hh24:mi:ss‘), 21133.91, 50, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1024, ‘冯爱敏‘, ‘110101196907283840‘, ‘女‘, to_date(‘18-07-1969‘, ‘dd-mm-yyyy‘), ‘营销专员‘, to_date(‘12-09-2005 22:41:06‘, ‘dd-mm-yyyy hh24:mi:ss‘), 3360.91, 20, null, 50000.00);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1025, ‘薛栓成‘, ‘110101400710051   ‘, ‘男‘, to_date(‘10-07-1940‘, ‘dd-mm-yyyy‘), ‘网络营销师‘, to_date(‘03-09-2007 14:55:06‘, ‘dd-mm-yyyy hh24:mi:ss‘), 12136.65, 40, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1026, ‘牛伟伟‘, ‘11010119851120602X‘, ‘女‘, to_date(‘20-11-1985‘, ‘dd-mm-yyyy‘), ‘岗位分析师‘, to_date(‘24-11-2011 16:08:38‘, ‘dd-mm-yyyy hh24:mi:ss‘), 6622.66, 30, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1027, ‘郭香云‘, ‘110101196010154525‘, ‘女‘, to_date(‘15-10-1960‘, ‘dd-mm-yyyy‘), ‘网络营销师‘, to_date(‘03-05-2005 13:01:22‘, ‘dd-mm-yyyy hh24:mi:ss‘), 26436.18, 50, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1028, ‘朱花枝‘, ‘110101195605154028‘, ‘女‘, to_date(‘15-05-1956‘, ‘dd-mm-yyyy‘), ‘研发‘, to_date(‘11-09-2007 07:41:01‘, ‘dd-mm-yyyy hh24:mi:ss‘), 10095.22, 50, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1029, ‘李岗‘, ‘110101196505163095‘, ‘男‘, to_date(‘16-05-1965‘, ‘dd-mm-yyyy‘), ‘岗位分析师‘, to_date(‘09-11-2007 17:26:38‘, ‘dd-mm-yyyy hh24:mi:ss‘), 23928.84, 30, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1030, ‘李军会‘, ‘110101197706152524‘, ‘男‘, to_date(‘15-06-1977‘, ‘dd-mm-yyyy‘), ‘营销专员‘, to_date(‘12-05-2007 19:48:21‘, ‘dd-mm-yyyy hh24:mi:ss‘), 3492.19, 20, null, 25000.00);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1031, ‘孙龙举‘, ‘110101198908306037‘, ‘男‘, to_date(‘30-08-1989‘, ‘dd-mm-yyyy‘), ‘运维工程师‘, to_date(‘24-11-2011 16:08:38‘, ‘dd-mm-yyyy hh24:mi:ss‘), 4323.84, 30, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1032, ‘韩朝旭‘, ‘110101199003270513‘, ‘男‘, to_date(‘27-03-1900‘, ‘dd-mm-yyyy‘), ‘人力资源师‘, to_date(‘11-09-2010 17:54:30‘, ‘dd-mm-yyyy hh24:mi:ss‘), 13740.92, 40, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1033, ‘孙少光‘, ‘110101198809274535‘, ‘男‘, to_date(‘27-09-1988‘, ‘dd-mm-yyyy‘), ‘网络营销师‘, to_date(‘24-11-2011 16:08:38‘, ‘dd-mm-yyyy hh24:mi:ss‘), 19778.62, 50, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1035, ‘邓香敏‘, ‘110101196607163109‘, ‘女‘, to_date(‘16-07-1966‘, ‘dd-mm-yyyy‘), ‘人力资源师‘, to_date(‘12-04-2007 17:47:14‘, ‘dd-mm-yyyy hh24:mi:ss‘), 29463.38, 40, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1037, ‘霍振方‘, ‘110101198411070014‘, ‘男‘, to_date(‘07-11-1984‘, ‘dd-mm-yyyy‘), ‘讲师‘, to_date(‘24-11-2011 16:08:38‘, ‘dd-mm-yyyy hh24:mi:ss‘), 23731.31, 40, 1087, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1038, ‘许双鸽‘, ‘110101781217004   ‘, ‘女‘, to_date(‘17-12-1978‘, ‘dd-mm-yyyy‘), ‘网络营销师‘, to_date(‘05-09-2007 18:45:00‘, ‘dd-mm-yyyy hh24:mi:ss‘), 16512.52, 30, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1040, ‘张春红‘, ‘110101197806176089‘, ‘女‘, to_date(‘17-06-1978‘, ‘dd-mm-yyyy‘), ‘运维工程师‘, to_date(‘21-11-2004 06:52:30‘, ‘dd-mm-yyyy hh24:mi:ss‘), 31728.83, 10, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1041, ‘卢玉莲‘, ‘110101510606004   ‘, ‘女‘, to_date(‘06-06-1951‘, ‘dd-mm-yyyy‘), ‘人力资源师‘, to_date(‘30-03-2009 17:05:45‘, ‘dd-mm-yyyy hh24:mi:ss‘), 17596.43, 40, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1042, ‘李军会‘, ‘110101197706152524‘, ‘男‘, to_date(‘15-06-1977‘, ‘dd-mm-yyyy‘), ‘讲师‘, to_date(‘13-06-2008 03:24:47‘, ‘dd-mm-yyyy hh24:mi:ss‘), 8443.59, 50, 1008, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1043, ‘朱水娃‘, ‘110101195210033512‘, ‘男‘, to_date(‘03-10-1952‘, ‘dd-mm-yyyy‘), ‘讲师‘, to_date(‘11-10-2009 03:40:53‘, ‘dd-mm-yyyy hh24:mi:ss‘), 9123.09, 30, 1008, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1045, ‘高大荣‘, ‘110101195504073528‘, ‘女‘, to_date(‘07-04-1955‘, ‘dd-mm-yyyy‘), ‘考试专员‘, to_date(‘07-12-2005 14:56:05‘, ‘dd-mm-yyyy hh24:mi:ss‘), 4000.00, 10, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1046, ‘秦付根‘, ‘110101195301034035‘, ‘男‘, to_date(‘03-01-1953‘, ‘dd-mm-yyyy‘), ‘讲师‘, to_date(‘10-12-2004 22:51:51‘, ‘dd-mm-yyyy hh24:mi:ss‘), 16420.33, 30, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1047, ‘樊增妮‘, ‘110101410715352   ‘, ‘女‘, to_date(‘15-07-1941‘, ‘dd-mm-yyyy‘), ‘网络营销师‘, to_date(‘02-12-2005 14:41:54‘, ‘dd-mm-yyyy hh24:mi:ss‘), 13316.01, 20, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1048, ‘宋素敏‘, ‘11010119720111458X‘, ‘女‘, to_date(‘11-02-1972‘, ‘dd-mm-yyyy‘), ‘岗位分析师‘, to_date(‘26-09-2004 12:15:57‘, ‘dd-mm-yyyy hh24:mi:ss‘), 2142.92, 40, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1049, ‘李记‘, ‘110101194803256012‘, ‘男‘, to_date(‘25-03-1948‘, ‘dd-mm-yyyy‘), ‘网络营销师‘, to_date(‘23-03-2006 19:12:45‘, ‘dd-mm-yyyy hh24:mi:ss‘), 13866.09, 50, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1050, ‘秦单风‘, ‘110101198911153625‘, ‘女‘, to_date(‘15-11-1989‘, ‘dd-mm-yyyy‘), ‘考试专员‘, to_date(‘21-10-2012 05:31:34‘, ‘dd-mm-yyyy hh24:mi:ss‘), 21419.38, 40, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1051, ‘秦占豪‘, ‘110101198509034011‘, ‘男‘, to_date(‘03-09-1985‘, ‘dd-mm-yyyy‘), ‘讲师‘, to_date(‘24-11-2011 16:08:38‘, ‘dd-mm-yyyy hh24:mi:ss‘), 31564.79, 40, 1087, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1054, ‘张利娟‘, ‘110101197901173062‘, ‘女‘, to_date(‘17-01-1979‘, ‘dd-mm-yyyy‘), ‘网络营销师‘, to_date(‘08-05-2011 22:37:13‘, ‘dd-mm-yyyy hh24:mi:ss‘), 7419.99, 50, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1055, ‘陈向琼‘, ‘11010119871010354X‘, ‘男‘, to_date(‘10-10-1987‘, ‘dd-mm-yyyy‘), ‘讲师‘, to_date(‘24-11-2011 16:08:38‘, ‘dd-mm-yyyy hh24:mi:ss‘), 4000.00, 10, 1087, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1056, ‘杨晓磊‘, ‘110101199105106079‘, ‘男‘, to_date(‘10-05-1991‘, ‘dd-mm-yyyy‘), ‘研发‘, to_date(‘05-04-2012 22:16:05‘, ‘dd-mm-yyyy hh24:mi:ss‘), 20812.41, 30, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1057, ‘黄芳菊‘, ‘110101196611133520‘, ‘女‘, to_date(‘13-11-1966‘, ‘dd-mm-yyyy‘), ‘网络营销师‘, to_date(‘04-07-2008 17:36:20‘, ‘dd-mm-yyyy hh24:mi:ss‘), 12711.46, 40, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1058, ‘李红勤‘, ‘110101197209084047‘, ‘女‘, to_date(‘08-09-1972‘, ‘dd-mm-yyyy‘), ‘运维工程师‘, to_date(‘01-03-2007 05:57:34‘, ‘dd-mm-yyyy hh24:mi:ss‘), 21119.95, 30, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1060, ‘薛栓成‘, ‘110101400710051   ‘, ‘男‘, to_date(‘10-07-1940‘, ‘dd-mm-yyyy‘), ‘考试专员‘, to_date(‘22-08-2007 08:06:47‘, ‘dd-mm-yyyy hh24:mi:ss‘), 24544.66, 40, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1061, ‘高发娃‘, ‘110101192905226032‘, ‘男‘, to_date(‘22-05-1929‘, ‘dd-mm-yyyy‘), ‘运维工程师‘, to_date(‘12-12-2004 22:49:04‘, ‘dd-mm-yyyy hh24:mi:ss‘), 23458.34, 10, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1062, ‘李新昌‘, ‘110101196403106013‘, ‘男‘, to_date(‘10-03-1964‘, ‘dd-mm-yyyy‘), ‘研发‘, to_date(‘01-04-2011 18:00:33‘, ‘dd-mm-yyyy hh24:mi:ss‘), 18605.46, 40, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1065, ‘赵永刚‘, ‘110101197507310014‘, ‘男‘, to_date(‘31-07-1975‘, ‘dd-mm-yyyy‘), ‘岗位分析师‘, to_date(‘05-12-2009 15:00:29‘, ‘dd-mm-yyyy hh24:mi:ss‘), 3155.96, 20, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1067, ‘冯世伟‘, ‘110101198811154532‘, ‘男‘, to_date(‘15-11-1988‘, ‘dd-mm-yyyy‘), ‘讲师‘, to_date(‘24-11-2011 16:08:38‘, ‘dd-mm-yyyy hh24:mi:ss‘), 17854.88, 40, 1087, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1068, ‘张延付‘, ‘110101197005233514‘, ‘男‘, to_date(‘23-05-1970‘, ‘dd-mm-yyyy‘), ‘岗位分析师‘, to_date(‘21-05-2009 10:16:16‘, ‘dd-mm-yyyy hh24:mi:ss‘), 24294.43, 30, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1070, ‘陈粉‘, ‘110101195801206040‘, ‘女‘, to_date(‘20-01-1958‘, ‘dd-mm-yyyy‘), ‘营销专员‘, to_date(‘29-06-2011 21:27:04‘, ‘dd-mm-yyyy hh24:mi:ss‘), 17708.56, 20, null, 600.00);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1071, ‘张根祥‘, ‘110101194412126513‘, ‘男‘, to_date(‘12-12-1944‘, ‘dd-mm-yyyy‘), ‘岗位分析师‘, to_date(‘06-10-2006 12:14:34‘, ‘dd-mm-yyyy hh24:mi:ss‘), 8802.52, null, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1074, ‘李秋彩‘, ‘110101197411186020‘, ‘女‘, to_date(‘18-11-1974‘, ‘dd-mm-yyyy‘), ‘考试专员‘, to_date(‘09-04-2005 01:11:29‘, ‘dd-mm-yyyy hh24:mi:ss‘), 19315.97, 40, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1075, ‘李建玲‘, ‘110101198110164423‘, ‘女‘, to_date(‘16-10-1981‘, ‘dd-mm-yyyy‘), ‘运维工程师‘, to_date(‘24-11-2011 16:08:38‘, ‘dd-mm-yyyy hh24:mi:ss‘), 9023.25, 50, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1076, ‘张仙‘, ‘110101530824316   ‘, ‘女‘, to_date(‘24-08-1953‘, ‘dd-mm-yyyy‘), ‘考试专员‘, to_date(‘09-05-2011 11:15:29‘, ‘dd-mm-yyyy hh24:mi:ss‘), 8654.83, 40, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1077, ‘朱金典‘, ‘110101196810023531‘, ‘男‘, to_date(‘02-10-1968‘, ‘dd-mm-yyyy‘), ‘营销专员‘, to_date(‘11-01-2008 11:13:31‘, ‘dd-mm-yyyy hh24:mi:ss‘), 6687.97, 20, null, 2700.00);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1079, ‘孙玉环‘, ‘110101195006056047‘, ‘女‘, to_date(‘05-06-1950‘, ‘dd-mm-yyyy‘), ‘考试专员‘, to_date(‘17-11-2008 12:48:12‘, ‘dd-mm-yyyy hh24:mi:ss‘), 7490.24, 20, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1080, ‘邢中景‘, ‘110101198208284519‘, ‘男‘, to_date(‘28-08-1982‘, ‘dd-mm-yyyy‘), ‘运维工程师‘, to_date(‘24-11-2011 16:08:38‘, ‘dd-mm-yyyy hh24:mi:ss‘), 24990.57, 40, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1081, ‘韩巧真‘, ‘110101198404190026‘, ‘女‘, to_date(‘19-04-1984‘, ‘dd-mm-yyyy‘), ‘人力资源师‘, to_date(‘24-11-2011 16:08:38‘, ‘dd-mm-yyyy hh24:mi:ss‘), 9880.26, 40, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1084, ‘杜巧琴‘, ‘110101196201036089‘, ‘女‘, to_date(‘03-01-1962‘, ‘dd-mm-yyyy‘), ‘岗位分析师‘, to_date(‘13-01-2011 16:11:23‘, ‘dd-mm-yyyy hh24:mi:ss‘), 21655.36, 20, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1085, ‘席妞娃‘, ‘110101194601154026‘, ‘女‘, to_date(‘15-01-1946‘, ‘dd-mm-yyyy‘), ‘运维工程师‘, to_date(‘15-08-2008 06:36:11‘, ‘dd-mm-yyyy hh24:mi:ss‘), 24615.12, 20, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1087, ‘薛素粉‘, ‘110101196701044528‘, ‘女‘, to_date(‘04-01-1967‘, ‘dd-mm-yyyy‘), ‘讲师‘, to_date(‘10-09-2007 06:07:14‘, ‘dd-mm-yyyy hh24:mi:ss‘), 12357.56, null, 1008, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1088, ‘王雪英‘, ‘110101193311264521‘, ‘女‘, to_date(‘26-11-1933‘, ‘dd-mm-yyyy‘), ‘岗位分析师‘, to_date(‘18-02-2006 23:37:15‘, ‘dd-mm-yyyy hh24:mi:ss‘), 23670.53, 10, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1089, ‘刘秀菊‘, ‘110101530414306   ‘, ‘女‘, to_date(‘14-04-1953‘, ‘dd-mm-yyyy‘), ‘研发‘, to_date(‘11-09-2004 18:17:49‘, ‘dd-mm-yyyy hh24:mi:ss‘), 22608.20, null, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1090, ‘刘芳芳‘, ‘110101198912216025‘, ‘女‘, to_date(‘21-12-1989‘, ‘dd-mm-yyyy‘), ‘网络营销师‘, to_date(‘10-10-2012 00:24:11‘, ‘dd-mm-yyyy hh24:mi:ss‘), 9749.45, 30, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1091, ‘郝方方‘, ‘110101198605165580‘, ‘女‘, to_date(‘16-05-1986‘, ‘dd-mm-yyyy‘), ‘运维工程师‘, to_date(‘24-11-2011 16:08:38‘, ‘dd-mm-yyyy hh24:mi:ss‘), 5944.72, 40, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1092, ‘赵利萍‘, ‘110101196712063564‘, ‘女‘, to_date(‘06-12-1967‘, ‘dd-mm-yyyy‘), ‘岗位分析师‘, to_date(‘01-08-2006 17:26:08‘, ‘dd-mm-yyyy hh24:mi:ss‘), 4575.09, 30, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1093, ‘杨联星‘, ‘110101195312284013‘, ‘男‘, to_date(‘28-12-1953‘, ‘dd-mm-yyyy‘), ‘考试专员‘, to_date(‘27-10-2009 08:41:47‘, ‘dd-mm-yyyy hh24:mi:ss‘), 24545.93, 40, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1094, ‘冯焕‘, ‘110101194205093524‘, ‘女‘, to_date(‘09-05-1942‘, ‘dd-mm-yyyy‘), ‘运维工程师‘, to_date(‘27-09-2010 18:25:55‘, ‘dd-mm-yyyy hh24:mi:ss‘), 21391.42, 50, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1096, ‘杨晓雨‘, ‘110101198910070043‘, ‘女‘, to_date(‘07-10-1989‘, ‘dd-mm-yyyy‘), ‘营销专员‘, to_date(‘07-08-2013 05:49:14‘, ‘dd-mm-yyyy hh24:mi:ss‘), 4161.31, 20, null, 2322.00);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1097, ‘柴帅友‘, ‘110101198510254038‘, ‘男‘, to_date(‘25-10-1985‘, ‘dd-mm-yyyy‘), ‘网络营销师‘, to_date(‘24-11-2011 16:08:38‘, ‘dd-mm-yyyy hh24:mi:ss‘), 7805.94, 50, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1098, ‘韩国强‘, ‘110101621016003   ‘, ‘男‘, to_date(‘16-10-1962‘, ‘dd-mm-yyyy‘), ‘研发‘, to_date(‘01-09-2007 12:30:52‘, ‘dd-mm-yyyy hh24:mi:ss‘), 13755.87, null, null, null);

insert into TEACHER (TNO, TNAME, TID, GENDAR, BIRTHDATE, JOB, HIREDATE, SAL, DEPTNO, MGRNO, COMM)
values (1099, ‘王参妮‘, ‘11010119490831352X‘, ‘女‘, to_date(‘31-08-1949‘, ‘dd-mm-yyyy‘), ‘岗位分析师‘, to_date(‘11-10-2005 13:17:18‘, ‘dd-mm-yyyy hh24:mi:ss‘), 26627.94, 30, null, null);

commit;

数据库脚本

这个有需求一点数学基础,应该初中或者高中都有讲过

1.并集 union(重复数据只显示一次)

--01.并集 union:  得到的结果集是多条slq执行的结果集的集合,重复数据只显示一次

select tno from teacher where tno<1020
union
select tno from teacher where tno>1025

1.并集 union all(重复数据显示多次)

--01.并集 union all:  重复的数据只显示多次
select tno from teacher where tno<1020
union all
select tno from teacher where tno>1010

2.交集 insersect

--02.交集intersect:  取俩个结果集中的公共部分
select tno from teacher where tno<1020
intersect
select tno from teacher where tno>1010

3.补集 minus

--03.补集minus:要求第一条sql语句的查询结果数>第二条sql语句的查询结果数,并且第二个结果集都在第一个结果集中存在
select tno from teacher where tno<1025
minus
select tno from teacher where tno<1020

原文地址:https://www.cnblogs.com/DawnCHENXI/p/9026398.html

时间: 2024-11-08 21:09:50

Oracle-11:联合查询的相关文章

Oracle ODI 12c之多表联合查询以及定时任务设置

本文介绍如何通过ODI进行多表联合查询并设置定时任务.准备工作如下: 准备物理方案和逻辑方案: 创建模型并通过"逆向工程"同步方案: 创建项目(根据实际情况创建或者使用现有的): 确保源表和目标表都有主键存在.以上内容的前三点可以参考我博客中的相关文章. 一.Preparing 1.1 源SQL语句 SELECT a.ID, a.ORG_ID, a.NAME_ID, a.EVR_ID, a.PACKAGE_ARCH_ID, a.PACKAGE_GROUP, a.RPM_VERSION,

Oracle数据库-多表联合查询&amp;子查询

多表联合查询 当需要获取的数据分布在多张中,考虑使用联合查询1.SQL92方式2.SQL99方式 SQL92方式 1.笛卡尔积:将多个表的数据进行一一对应,所得到结果为多表的笛卡尔积. 结果的数量为所有表的数量的乘积. select * from emp,dept 2.等值连接筛选 概念:先做表的笛卡尔积,然后筛选,筛选条件为等值筛选. 注意:条件为字段的值相同来进行筛选,字段的名字可以不同 查询员工姓名,工作,薪资,部门名称 select * from emp,dept where emp.d

Oracle联合查询

select * from teacher--联合查询 --01.union (并集)select tno from teacher where tno>1080 union(select tno from teacher where tno>1090)--02.union all(并集并且显示重复的数据)select tno from teacher where tno>1080 union all(select tno from teacher where tno>1090)-

【Oracle】曾经的Oracle学习笔记(4-7)多表联合查询,子查询,动态条件查询

一.多表联合查询 二.子查询 三.动态条件查询 LESSON 4 Displaying Data from Multiple Tables-------------------------------------------------------- 查询s_emp表中最大的工资数,并且显示出这个最大工资数的员工名字 select last_name,max(salary)from s_emp; 多表查询 查询多张表的时候会产生笛卡尔积 为了防止笛卡尔积的产生,我们需要使用某些条件把两张表或多张

sphinx的联合查询(sphinx配置篇)

下面举例说明,sphinx的联合查询用法. 一,添加二张测试表和数据 1,users表和数据 mysql> desc users; +----------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +----------+-------------+------+-----+---------+----------------+ | 

在db2中 两个数据库之间的两个表的联合查询

大家好,今天遇到了在db2中 两个数据库之间的两个表的联合查询我知道oracle中有dblink,可是不知到db2的两个数据库联合查询怎么处理我找了类似于比如两个数据库: db1,db2用户名密码select * from db1.用户名.密码,db2.用户名.密码 where db1.NM=db2.NM可是这样不好用啊请各位帮忙谢谢 DB2有联邦数据库的,你可以查一下. 1.要看目录数据库请用:db2 list db directory这些信息应该是放系统表中.(既不是什么注册表.也不是什么文

oracle之sql查询二

此文章为http://huangsir007.blog.51cto.com/6159353/1854818该片的后续 关于数据库语言查询: SQL> show parameter nls_language; NAME                                 TYPE        VALUE ------------------------------------ ----------- ------------------------------ nls_languag

2015-10-19 SQL(新建数据库、创建表、注释、查询语句、新增、更新、删除、联合查询)

1.认识数据库并新建: 1)打开数据库,连接到服务器. 2)服务里类型不用管. 3)服务器名称:打个点“.”表示服务器在本地计算机,如果是托管在别人的服务器上,就输入服务器IP地址. 4)身份验证:如果是windows身份验证,就需要有管理员权限.一般托管在别人的服务器上,(包括正常情况下),都是用SQL身份验证,需要输入sa和密码(密码就是安装时让输入的密码). 2.  建立数据库: 在建立数据库名称时(各种名称时),都遵守一个命名规则: 1)用英文命名 2)每个单词的首字母大写(驼峰原则:首

浅谈数据库联合查询

http://www.cnblogs.com/Candies/p/4142576.html 本文介绍以下内容: LFET JOIN.RIGHT JOIN.INNER JOIN.UNION.UNION ALL.FULL JOIN等! 测试数据(以下数据未经考证,非真实有效数据,仅作为本次学习的测试数据!) 全国大学排名TOP20 No. 校名 地区 校长 类型 1 北京大学 北京 周其凤 综合 2 清华大学 北京 顾秉林 理工 3 浙江大学 浙江 杨卫 综合 4 复旦大学 上海 杨玉良 综合 5

MySQL DML操作--------多表联合查询实战

1. 背景 * 多表联合查询是把不同表的记录到一起的一种方式 * 在SQL标准中规划的联合(join)大致分内连接,外连接,全连接.其中外连接又分左外连接,右外连接. 2. 内连接例子 (inner join) [ 员工 --> 部门 ] * 查看员工表[ employees ]和部门表[ departments ]结构 mysql> desc employees; +-----------+---------------+------+-----+---------+------------