select关键字

作用:检索“列”

注意:1.select后面的列可以起别名(查询的显示结果)

1) 列名后面一个空格后添加别名(别名中不许有“空格”)

2) 列名后面一个空格后使用双引号添加别名

3) 列名后面一个空格后使用as关键字,在as后面添加别名

2.distinct用于对显示结果的去重

1) distinct必须放在select后面

2) 如果查询有多列,必须满足多列值都相同时,方可去重。

from关键字

作用:检索“表”

注意:检索的表后可以添加别名(别名不需要被双引号引起)

作用:检索“列”

--1.

  1. --单行注释

--2.

  1. /*
  2.  
  3. 多行注释
  4.  
  5. */

select

--select关键字第一个句型

--select [列1,列2, ... ,列N] from  表

--例:查询员工姓名和薪水

  1. select emp.ename,emp.sal from emp;

--给表取别名

  1. select ename,sal,e.deptno from emp e,dept d;

--oracle中,列名和表名默认不区分大小写,数据是区分大小写的

--给列取别名

--例:查询员工姓名和年薪

--方式一

  1. select ename,sal*12年薪 from emp;

--方式二

  1. select ename,sal*12 "ysal" from emp;

--方式三

  1. select ename,sal*12 as "ysal" from emp;

--例子:查询公司有哪些职位

--使用distinct去除显示重复的结果 必须放在Select关键字后面

  1. select distinct ename,job from emp;

--distinct后面跟多个列时,必须保证多列都重复才可以去除重复内容

--distinct只能放在select的后面

--错误的SQL:select  ename,distinct job from emp;

(意思变成我想查找emp中 的ename 和distinct列)

Where

--where关键字

--作用:过滤行

Select *from表名 where  列名 。。。

  • --=,!=,<>,<,>,<=,>=,any,some,all
  • -- is null,is not null(判断是否为空  0.00 不等于空)
  • -- between x and y(在...and...之间)
  • --and、or 、not(与或非)
  • -- in(list),not in(list)(在,不是在)
  • -- exists(sub-query)、not exists(sub-query)
  • -- like _ ,%,escape ‘\‘ _\% escape ‘\’

--例:查询工资大于2000的员工信息

  1. select * from emp where sal <=

--=,!=,<>,<,>,<=,>=,any,some,all

--查询员工信息,条件:薪水要大于1000,薪水还要大于1500,薪水还要大于2000

  1. select * from emp where sal != any(1000,1500,2000)

--some和any用法一样

--all表示所有

-- is null,is not null(判断是否为空  0.00 不等于空)

  1. select * from emp where comm is not null;

--错误:select * from emp where comm = null

-- between x and y(在...and...之间)

--查询员工薪水在2000-3000的员工信息

  1. select * from emp where sal between 2000 and

--and、or 、not(与或非)

  1. select * from emp where sal >= 2000 and sal <=

-- in(list),not in(list)(在,不是在)

--查询职务为MANAGER和ANALYST的员工信息

  1. select * from emp where job in ('MANAGER','ANALYST')

--查询工资不为3000和5000的员工信息

  1. select * from emp where sal not in (3000,5000)

-- exists(sub-query)、not exists(sub-query)(先查询括号内的若为ture则执行括号外的 )

  1. select * from emp where exists(select * from dept where deptno != 50)
  • -- like _ ,%,escape ‘\‘ _\% escape ‘\’
  • --like关键字
  • --模糊查询,有两个特殊的符号"%" ,"_"
  • --“%”表示匹配零个或若干字符
  • --“_”表示匹配一个字符

--查询:员工姓名中含有“M”的员工信息

  1. select * from emp where ename like '%M%'

--查询:员工姓名中第二个字母是“M”的员工信息

  1. select * from emp where ename like '_M%'

--查询:员工姓名中第三个字母是“O”的员工信息

  1. select * from emp where ename like '__O%'

--查询:员工姓名中倒数第二个字母为“E”的员工信息

  1. select * from emp where ename like '%E_'

--查询:员工姓名中含有“%”的员工信息

  1. select * from emp where ename like '%\%%' escape '\'

--插入一条信息:insert into emp(empno,ename) values(9527,'huan%an');

作业

[if !supportLists]1、[endif]查询部门编号为10的员工信息

  1. select *from emp where deptno =10 ;

[if !supportLists]2、[endif]查询年薪大于3万的人员的姓名与部门编号

  1. select ename,sal,deptno from emp where sal*12 >30000 ;

[if !supportLists]3、[endif]查询佣金为null的人员姓名与工资

  1. select ename,sal from emp where comm is null ;

[if !supportLists]4、[endif]查询工资大于1500且 and 含有佣金的人员姓名

  1. select ename from emp where sal>1500 and comm is not null ;

[if !supportLists]5、[endif]查询工资大于1500或 or含有佣金的人员姓名

  1. select ename from emp where sal>1500 or comm is not null ;

[if !supportLists]6、[endif]查询姓名里面含有S员工信息 工资、名称

  1. select ename,sal from emp where ename like '%S%';

[if !supportLists]7、[endif]求姓名以J开头第二个字符O的员工姓名的与工资

  1. select ename,sal from emp where ename like 'JO%';

[if !supportLists]8、[endif]求包含%的雇员姓名

  1. select ename from emp where ename like '%\%%' escape '\';

9、使用in查询部门名称为 SALES 和 RESEARCH 的雇员姓名、工资、部门编号

  1. select e.ename,e.sal,e.deptno
  2.  
  3. from emp e
  4.  
  5. where e.deptno in(select d.deptno
  6.  
  7. from DEPT d
  8.  
  9. where d.dname ='SALES'or
  10.  
  11. d.dname = 'RESEARCH');

10、使用exists查询部门名称为SALES和RESEARCH 的雇员姓名、工资、部门编号

  1. select e.ename, e.sal, e.deptno
  2.  
  3. from emp e
  4.  
  5. where exists (select d.deptno
  6.  
  7. from dept d
  8.  
  9. where (d.dname = 'SALES'
  10.  
  11. or d.dname = 'RESEARCH') and d.deptno = e.deptno);

Oracle day01 select where关键字的更多相关文章

  1. Oracle中使用escape关键字实现like匹配特殊字符,以及&字符的转义

    转:http://blog.chinaunix.net/uid-26896647-id-3433968.html 问题描述:如果在一个表中的一个字段上存在'&',  '_',  '%'这样的特 ...

  2. oracle实现like多关键字查询

    oracle实现like多关键字查询: select * from contract_info tt where 1=1 and REGEXP_LIKE(tt.contract_name,'关键字1| ...

  3. 数据库Oracle的select用法(部分)

    Oracle的select用法(部分): 1.查询所有: select * from employees; 2.加上where子句:用选择限制行 select * from employees whe ...

  4. Oracle【select from 语句】

    Oracle[select from  语句] 1.select基本功能介绍1)投影操作:结果集是源表中的部分“列”2)选择操作:结果集是源表中的部分“行”3)选择操作+投影操作:结果集是源表中的部分 ...

  5. ORACLE-SELECT学习

    (一)select格式:SELECT [ ALL | DISTINCT ] <字段表达式1[,<字段表达式2[,…] FROM <表名1>,<表名2>[,…] [W ...

  6. Oracle 数据库(oracle Database)Select 多表关联查询方式

    Oracle数据库中Select语句语法及介绍 SELECT [ ALL | DISTINCT ] <字段表达式1[,<字段表达式2[,…] FROM <表名1>,<表名 ...

  7. {MySQL的逻辑查询语句的执行顺序}一 SELECT语句关键字的定义顺序 二 SELECT语句关键字的执行顺序 三 准备表和数据 四 准备SQL逻辑查询测试语句 五 执行顺序分析

    MySQL的逻辑查询语句的执行顺序 阅读目录 一 SELECT语句关键字的定义顺序 二 SELECT语句关键字的执行顺序 三 准备表和数据 四 准备SQL逻辑查询测试语句 五 执行顺序分析 一 SEL ...

  8. 解析oracle对select加锁的方法以及锁的查询 转

    转自 https://www.jb51.net/article/37587.htm 本篇文章是对oracle对select加锁的方法以及锁的查询进行了详细的分析介绍,需要的朋友参考下 解析oracle ...

  9. Oracle中select使用别名

    1 .将字段用as转换成别名. 2 .直接在字段的名字后面跟别名. 3 .在字段后面用双引号引起的别名.   我的朋友 大鬼不动 最近访客 fhwlj kochiyas 大極星 Alz__ deser ...

随机推荐

  1. 《JavaScript DOM编程艺术》学习笔记(一)

    这本书是我听说学习前端基础入门书籍,于是就开始看了,大概是从5月10号开始看的吧,一直看到现在,差不多要看完了,书是挺厚的...286页,不过比起JAVASCRIPT权威指南来说还是差多了,权威指南才 ...

  2. Data Center手册(2): 安全性

    有个安全性有下面几种概念: Threat:威胁 Vulnerability: 安全隐患 Attack: 攻击 有关Threat 常见的威胁有下面几种 DoS(Denial of Service拒绝服务 ...

  3. Selenium自动化测试插件—Katalon的自述

    Katalon-一款好用的selenium自动化测试插件 Selenium 框架是目前使用较广泛的开源自动化框架,一款好的.基于界面的录制工具对于初学者来说可以快速入门:对于老手来说可以提高开发自动化 ...

  4. C++ Opencv remap()重映射函数详解及使用示例

    一.重映射及remap()函数介绍 重映射,就是把一幅图像中某位置的像素放置到另一图像指定位置的过程.即: 在重映射过程中,图像的大小也可以同时发生改变.此时像素与像素之间的关系就不是一一对应关系,因 ...

  5. #Java学习之路——基础阶段(第七篇)

    我的学习阶段是跟着CZBK黑马的双源课程,学习目标以及博客是为了审查自己的学习情况,毕竟看一遍,敲一遍,和自己归纳总结一遍有着很大的区别,在此期间我会参杂Java疯狂讲义(第四版)里面的内容. 前言: ...

  6. [Swift]LeetCode703. 数据流中的第K大元素 | Kth Largest Element in a Stream

    Design a class to find the kth largest element in a stream. Note that it is the kth largest element ...

  7. [Swift]LeetCode736. Lisp 语法解析 | Parse Lisp Expression

    You are given a string expressionrepresenting a Lisp-like expression to return the integer value of. ...

  8. [Swift]LeetCode965. 单值二叉树 | Univalued Binary Tree

    A binary tree is univalued if every node in the tree has the same value. Return true if and only if ...

  9. [Swift]LeetCode1027. 最长等差数列 | Longest Arithmetic Sequence

    Given an array A of integers, return the length of the longest arithmetic subsequence in A. Recall t ...

  10. JVM基础系列第10讲:垃圾回收的几种类型

    我们经常会听到许多垃圾回收的术语,例如:Minor GC.Major GC.Young GC.Old GC.Full GC.Stop-The-World 等.但这些 GC 术语到底指的是什么,它们之间 ...