zoukankan      html  css  js  c++  java
  • sql基础知识回顾

    一:查询条件

       1:  >    <      =     >=     <=    !=   <>

     2:  and   or  

       3:  like 

       4:  in            not   in

       5:       between.......   and .....

       6:  is   null             is    not    null

       7:  any(任意一个)       all(所有

           这两个用于子查询

            例:select from student where 班级='01' and age > all (select age from student where 班级='02');   查询01班学生年龄大于02班所有的学生

                                      相当于:   select from student where 班级='01' and age > (select max(age) from student where 班级='02');

              select from student where 班级='01' and age > any (select age from student where 班级='02');   查询01班学生年龄大于02班任意学生

              相当于: select from student where 班级='01' and age > (select min(age) from student where 班级='02');

       8:  distinct    去重复

    二:排序

            order    by

             例如:select  deptno, sal, from emp order by deptno asc,sal desc;    

          其中:asc升序   desc降序

    三:分组

         group by(按什么分组)+  having(条件限制)

         例如:  select  * from  emp group by deptno having max(sal)>4000;

    四:计算函数

      1:  max     min

      2:avg(平均值) sum(合计)

      3:count(计算表中查询出来的行数)

    五:分页查询

      rownum(伪列)  返回标识行数据顺序的数字

      select * from (select ruwnum rm ,e.* from emp) where rm   between  1  and 15;

    6:decode函数

       DECODE(value,if1,then1,if2,then2,if3,then3,...,else),表示如果value等于if1时,DECODE函数的结果返回then1,...,如果不等于任何一个if值,则返回else。

      例如:select * from decode(job,'teacher',sal*1.2,'saleman',sal*1.5,sal) from emp;

     

        

      

      

       

  • 相关阅读:
    Mybatis-Plus的应用场景及注入SQL原理分析
    玩转直播系列之消息模块演进(3)
    Kafka万亿级消息实战
    玩转直播系列之RTMP协议和源码解析(2)
    Tars-Java客户端源码分析
    玩转直播系列之从 0 到 1 构建简单直播系统(1)
    如何把 Caffeine Cache 用得如丝般顺滑?
    kubenets 配置Pod的 /etc/hosts
    kubernetes之多容器部署pod以及通信
    k8s master调度pod
  • 原文地址:https://www.cnblogs.com/jcfxl/p/8835487.html
Copyright © 2011-2022 走看看