• 基础查询(一)


    表的梳理

    部门表

     

    deptno:部门编号

    dname:部门名称

    loc –location 地理位置

    员工表

     

    empno:员工编号

    ename:员工姓名

    job:工种

    mgr:上级

    hiredate:入职时间

    sal:薪水

    comm:津贴

    deptno:部门编号

    薪水等级表

     

    grade:等级

    losal-Lowestsal:最低薪水

    hisal-highestsal:最高薪水

    DML(Data manipulation language)

    数据库操纵语言(增删查改表中数据)

    基础查询

    1、查询单个字段

    select
    
    dept.dname
    
    from dept;
    
    
    
    select
    
    dname
    
    from demp;

    注意:select查询

    from:从哪里来 来自 特指表

    2、查询多个字段

    select 
    dname, loc
    from dept;

    3、将查询到的字段取别名

    select 
    ename as 雇员姓名
    from emp;
    
    select 
    ename 雇员姓名
    from emp;
    
    select 
    ename 雇员姓名
    from emp as e;

    给列和表名都可以取别名,as和不加as效果性能相同

    4、条件查询实例

    符号练习:#查询薪水=5000的员工

    1select 
    ename, sal, job
    from emp 
    where sal=5000;

    数字区间练习:#查询job是MANAGER且薪水大于2000小于2500

    2select 
    ename, job, sal 
    from emp 
    where sal between 2000 and 2500 and job='MANAGER';

    判空练习:#津贴为空且job是是manager且薪水大于2000且小于2500的员工

    3select 
    ename, job, sal, comm 
    from emp 
    where comm is null and sal between 2000 and 2500 and job=’MANAGER’;

    或or练习#津贴为空且job是manager且薪水大于2000且小于2500的员工 和job是salesman,comm=500 的员工

    4select
    ename, job, sal,comm
    from emp
    where (comm is null and sal between 2000 and 2500 job='MANAGER') 
    or (job='SALESMAN' and comm='500');

    in 练习#津贴为空 且job是manager  且薪水大于2000小于2500的员工 和job是salesman comm=500的员工,且同时查出薪水等于800 1600  3000的员工信息

    5select 
    ename,job,sal, comm
    from emp 
    where (comm is null and sal between 2000 and 2500 and job='MANAGER')
    or (job='SALESMAN' and comm=500) 
    or sal in(800, 1600, 3000);

    not 练习#查出薪水不等于800 和1600的员工

    6select 
    ename,job,sal,comm
    from emp 
    where not (sal=800 or sal=1600);

    #以j开头 以s结尾的员工

    7select 
    ename, job, sal
    from emp 
    where ename like 'J%S';

    #查看第二个字是O 一共5个字母

    8select
    ename, job, sal 
    from emp
    where ename like '_O___';

     

  • 相关阅读:
    C++ allocator
    C++操作符重载
    Theron (C++ concurrency library) 读后感
    第五章 [BX]和loop指令
    第四章 第一个程序
    第三章 寄存器(内存访问)
    第二章 寄存器
    第一章
    jquery下ajax异步执行操作笔记
    CSSFlex布局
  • 原文地址:https://www.cnblogs.com/HelloM/p/13545424.html
Copyright © 2020-2023  润新知