语法:

    1. select 查询列表 from 表明 where 筛选条件;

    1、分类:

    • 按条件表达式筛选:

    条件运算符:> < = != <>(不等) >= <=
    案例一:查询工资大于12000的员工信息

    1. select * from employees where salary>12000;

    案例二:查询部门编号不等于90号的员工名和部门编号

    1. select last_name,department_id from employees where department_id!=90;
    • 按逻辑表达式筛选:

    作用:连接条件表达式
    逻辑运算符:

    • and:两个条件都为true,结果为true,反之为false
    • or:只要有一个条件为true,则结果为true,反之为false
    • not:如果连接的条件本身为false,则结果为true,反之为false

    案例一:查询工资在10000到20000之间的员工名、工资、奖金

    1. select last_name,salary,commission_pct from employees where salary>10000 and salary<20000;
    1. 案例二:查询部门编号不是在90110之间的,或者工资高于15000的员工信息
    1. select *
    2. from employees
    3. where department_id<90 or department_id>110 or salary>15000;
    4. where not department_id>=90 and department_id<=110 or salary>15000;
    • 模糊查询:

    like,between and,in,is null

    • like
    • 案例一:查询员工名中包含字符a的员工信息
    • 字符型的值必须用单引号引起来
    • like一般与通配符搭配使用,%代表任意字符,包含0个字符,_代表任意单个字符

      1. select *
      2. from employees
      3. where last_name like '%a%';
    • 案例二:查询员工名中第三个字符为e,第五个字符为a的员工名和工资

      1. select last_name,salary
      2. from employees
      3. where last_name like '__e_a%';
    • 案例三:查询员工名中第二个字符为下划线的员工名

      1. select last_name
      2. from employees
      3. where last_name like '_\_%'
      4. where last_name like '_$_%' escape '$';
    • between and

    • 案例一:查询员工编号在100到120之间的员工信息
    • 包含临界值,且临界值顺序不能随意调换

      1. select *
      2. from employees
      3. where employee_id between 100 and 120;
    • in

    • 案例一:查询员工的工种编号是IT_PROG、AD_VP、AD_PRES的一个员工名和工种编号
    • in列表的值类型必须统一或兼容

      1. select last_name,job_id
      2. from employees
      3. where job_id in('IT_PROG','AD_VP','AD_PRES');
    • is null

    • 案例一:查询没有奖金的员工名和奖金率
    • 只可以判断null值

      1. select last_name,commission_pct
      2. from employees
      3. where commission_pct is null;
    • 安全等于: <=>

    • 案例一:查询没有奖金的员工名和奖金率

      1. select last_name,commission_pct
      2. from employees
      3. where commission_pct <=>null;
    • 案例二:查询工资为12000的员工信息

      1. select last_name,salary
      2. from employees
      3. where salary <=>12000;