zoukankan      html  css  js  c++  java
  • [学习笔记] Oracle运算符、连接符、结果去重、范围查询、模糊查询

    运算符

    符号 解释
    + 加法
    - 减法
    * 乘法
    / 除法,结果是浮点数
    = 等于
    > 大于
    < 小于
    <>或者!= 不等于
    >= 大于或者等于
    <= 小于或者等于
    AND 逻辑与
    OR 逻辑或
    NOT 逻辑非

    字符串连接符

    select '姓名:' || c.stuname || ', 课程:' || b.coursename || ', 成绩:' || a.score || '分。' as sxcj
       from score a, course b, stuinfo c
       where a.courseid = b.courseid
       and a.stuid = c.stuid;
    

    查询结果去重

    SELECT DISTINCT 列1,列2,列3... from 表名;
    
    select distinct b.coursename, t.score
       from score t, course b
       where t.courseid = b.courseid
       and t.courseid = 'R20180101';
    

    DISTINCT后面只有一个列时,表示的是单个字段查询结果去重

    DISTINCT后面有多个列时,表示的是多个字段组合的查询结果去重,即所有字段的值全部一样才去重。

    IN操作符

    select t.stuid,
           t.courseid,
           t.score,
           b.stuname,
           b.sex,
           b.age,
           b.classno,
           b.grade
      from score t, stuinfo b
     where t.stuid = b.stuid
       and t.courseid = 'R20180101'
       and t.score in ('85','89','79');
    

    BETWEEN...AND

    select t.stuid,
           t.courseid,
           t.score,
           b.stuname,
           b.sex,
           b.age,
           b.classno,
           b.grade
      from score t, stuinfo b
     where t.stuid = b.stuid
       and t.courseid = 'R20180101'
       and t.score between '70' and '95';
    

    LIKE模糊查询

    select * from STUINFO t where t.stuname like '张%';
    select * from STUINFO t where t.stuname like '张_';
    
    • %:表示零个或者多个任意字符。
    • _:表示一个任意字符。
    • :表示转义字符,“%”在字符串中表示字符“%”。
  • 相关阅读:
    ArcMap导出图层属性为excel表
    ArcMap面转为线
    vue(18)声明周期函数
    geoserver发布mbtiles文件
    docker部署geoserver
    vue(17)组件插槽slot的使用
    vue(16)父子组件之间直接相互访问
    MySQL常用查询语句积累
    数据库的基本设计
    HashMap学习
  • 原文地址:https://www.cnblogs.com/danhuang/p/12497127.html
Copyright © 2011-2022 走看看