--笛卡尔集
select empno,ename, 员工表.deptno, 部门表.deptno, dname
from 部门表, 员工表;

--添加合适的条件,可以避免笛卡尔集,从而得到正确的多表查询记录
select empno,ename, 员工表.deptno, 部门表.deptno, dname
from 部门表, 员工表
where 部门表.deptno = 员工表.deptno;

--查询员工信息,要求显示:员工号,姓名,职位,部门名称

--等值连接
select empno,ename,job,dname from emp, dept where emp.deptno = dept.deptno;

--多个条件的等值连接,使用AND操作符
select e.empno,e.ename,e.job,d.dname,d.deptno from emp e, dept d where e.deptno = d.deptno and e.deptno=10;

--显示所有员工的员工号、姓名、工资及其工资的等级。

select * from salgrade;

--非等值连接
select e.empno, e.ename, e.sal, s.grade from emp e, salgrade s where e.sal between losal and hisal;

--按部门统计员工的人数,要求显示:部门号,部门名称,人数

select d.deptno,d.dname,count(e.empno) from dept d, emp e where d.deptno = e.deptno group by d.deptno, d.dname;

select * from dept;

select * from emp where deptno=40;

--外连接
select d.deptno,d.dname,count(e.empno) from dept d, emp e where d.deptno = e.deptno(+) group by d.deptno, d.dname;

--自连接

--查询所有员工的姓名和直属上级的姓名
select e.ename,m.ename
from emp e, emp m
where e.mgr = m.empno;

--验证 ford-->jones
select * from emp;

--cross join
select d.dname, e.ename, d.deptno, e.deptno from dept d cross join emp e;
select count(*) from emp;
select count(*) from dept;

--natural join
--查询员工名、工资以及所在部门名称
select e.ename, e.sal, d.dname from dept d natural join emp e;

--内连接
--using子句
select e.ename,e.sal, d.dname from dept d join emp e using(deptno);

--通过on指定内连接的条件
select e.ename,e.sal, d.dname from dept d join emp e on d.deptno = e.deptno;

--内连接的关键字inner join, inner通常省略
select e.ename,e.sal, d.dname from dept d inner join emp e on d.deptno = e.deptno;

--左外连接
select e.ename,e.sal, d.dname from dept d left join emp e on d.deptno = e.deptno;

--右连接
select e.ename,e.sal, d.dname from dept d right join emp e on d.deptno = e.deptno;

--完全连接
select e.ename,e.sal, d.dname from dept d full join emp e on d.deptno = e.deptno;

--emp01
create table emp01
as
select * from emp where deptno in(10,20);

--emp02
create table emp02
as
select * from emp where deptno in(20,30);

--合并显示emp01表和emp02表所有雇员的部门编号、员工号、员工姓名。
--10号部门有3个、20号部门有5个、
select * from emp01;
--30号部门有6个、
select * from emp02;

--union 14个记录
select deptno, empno, ename from emp01
union
select deptno, empno, ename from emp02;

--union all
--通过部门号进行排序
select deptno, empno, ename from emp01
union all
select deptno, empno, ename from emp02
order by deptno;

--通过列值进行排序,1代表第一列
select deptno, empno, ename from emp01
union all
select deptno, empno, ename from emp02
order by 1;

--intersect
select deptno, empno, ename from emp01
intersect
select deptno, empno, ename from emp02;

--minus
select deptno, empno, ename from emp01
minus
select deptno, empno, ename from emp02;

Oracle数据库----查询的更多相关文章

  1. oracle数据库查询日期sql语句(范例)、向已经建好的表格中添加一列属性并向该列添加数值、删除某一列的数据(一整列)

    先列上我的数据库表格: c_date(Date格式)     date_type(String格式) 2011-01-01                   0 2012-03-07         ...

  2. python操作oracle数据库-查询

    python操作oracle数据库-查询 参照文档 http://www.oracle.com/technetwork/cn/articles/dsl/mastering-oracle-python- ...

  3. C#连接Oracle数据库查询数据

    C#连接Oracle数据库可以实现许多我们需要的功能,下面介绍的是C#连接Oracle数据库查询数据的方法,如果您对C#连接Oracle数据库方面感兴趣的话,不妨一看. using System; u ...

  4. 005.Oracle数据库 , 查询多字段连接合并,并添加文本内容

    /*Oracle数据库查询日期在两者之间*/ SELECT PKID , OCCUR_DATE, PKID || ' 曾经沧海难为水 ' ||TO_CHAR( OCCUR_DATE, ' yyyy/m ...

  5. 004.Oracle数据库 , 查询多字段连接合并

    /*Oracle数据库查询日期在两者之间*/ SELECT PKID , OCCUR_DATE, PKID || TO_CHAR( OCCUR_DATE, ' yyyy/mm/dd hh24:mi:s ...

  6. 001.Oracle数据库 , 查询日期在两者之间

    /*Oracle数据库查询日期在两者之间*/ SELECT OCCUR_DATE FROM LM_FAULT WHERE ( ( OCCUR_DATE >= to_date( '2017-05- ...

  7. oracle数据库查询常用语句

    1.查询SCOTT表中有多少表,并显示表的一些描述select * from all_tables WHERE owner='SCOTT' ; 2.查询oracle数据库版本select * from ...

  8. oracle数据库查询全系整理

    oracle数据库方面的知识到今天已经整理了12篇.当然,这不是终点,这只是一个开始,希望我写的文章可以帮助更多初学数据库的童鞋快速上手,如果你觉得文章对你有帮助,那么恭喜你已经入门了,数据库里面的知 ...

  9. oracle数据库查询和更新

    package sqltest; import java.sql.*; import parameter.BaseCanShu; public class PublicDbOracle { stati ...

  10. 2018.5.9 Oracle数据库查询命令

    0.查询所有数据(最简单,但是时间很久) select * from emp; Result: EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ----- - ...

随机推荐

  1. 设置InputBox等提示框的字体以及样式

    InputBox等窗体的字体大小设置方法 Graphics.DefFontData.Height:=48;  Graphics.DefFontData.Style:=[fsBold,fsItalic, ...

  2. 关于"云服务器被检测到对外攻击已阻断该服务器对其它服务器端口的访问"的解决措施

    前段时间阿里云大量发送云服务器对外攻击的信息到邮箱中,邮件信息大概如下: 您的云服务器(XX.XX.XX.XX)由于被检测到对外攻击,已阻断该服务器对其它服务器端口(TCP:XX)的访问,阻断预计将在 ...

  3. WinForm DataGridView制作表格

    1.  将背景颜色改为白色 this.dataGridView1.BackgroundColor = Color.White; 或 2. 禁止启用添加,启用编辑,启用删除 this.dataGridV ...

  4. Decision Tree

    Decision Tree builds classification or regression models in the form of a tree structure. It break d ...

  5. matplotlib简介

    python的matplotlib包可以帮助我们绘制丰富的图表,有助于我们的数据分析. matplotlib官方文档:matplotlib 本博客所有代码默认导入matplotlib.pyplot和n ...

  6. Linux SD卡建立两个分区

    本文主要介绍Linux 环境下 SD 卡建立两个分区的操作流程: 操作环境:Linux Ubuntu 2016.4 操作目的:将 SD 卡分为两个分区:第一分区格式为 FAT32,大小 500M.第二 ...

  7. ring3下利用WMI监视进程创建(vc版)

    #include "stdafx.h" #define _WIN32_DCOM #include <iostream> using namespace std; #in ...

  8. 基于Delphi实现客户端服务端通信Demo

    在开始之前我们需要了解下这个Demo功能是啥 我们可以看到这是两个小project,左边的project有服务端和客户端1,右边的project只有一个客户端2 效果就是当两个客户端各自分别输入正确的 ...

  9. c# log4net 配置使用

    新增配置文件log4net.config,内容如下 <?xml version="1.0" encoding="utf-8" ?> <conf ...

  10. 原生Js封装的产品图片360度展示

    挺简单的一段程序,但是效果不错: 1.把需要展示的36张图片先预加载到浏览器缓存里 2.给展示图片的div添加方法 3.通过鼠标左右移动的像素转换图片 在线效果预览:http://jsfiddle.n ...