MySQL-DML-condition query

  • DQL conditional query

    • Condition query: select field list from table name where condition list
    • comparison operator

      • Equal operator (=)
        • specific code
        • -- 1.查询姓名为‘杨逍’的员工
          select id,
                 username,
                 password,
                 name,
                 gender,
                 image,
                 job,
                 entrydate,
                 create_time,
                 update_time
          from tb_emp
          where name = '杨逍';
      • Not equal to operator (<> or !=)
        • The specific code is as follows
        • -- 5.查询密码不等于‘123456’的员工信息
          select id,
                 username,
                 password,
                 name,
                 gender,
                 image,
                 job,
                 entrydate,
                 create_time,
                 update_time
          from tb_emp
          where password != '123456';
      • greater than operator (>)
      • less than operator (<)
      • greater than or equal to operator (>=)
      • less than or equal to operator (<=)
        • The specific code is as follows
        • -- 2.查询id小于等于5的员工信息
          select id,
                 username,
                 password,
                 name,
                 gender,
                 image,
                 job,
                 entrydate,
                 create_time,
                 update_time
          from tb_emp
          where id <= 5;
      • BETWEEN.....AND....operator (including the most value)
        • The specific code is as follows
        • -- 6.查询入职日期在‘2000-0-01’(包含)到‘2010-01-01’(包含)之间的员工信息
          select id,
                 username,
                 password,
                 name,
                 gender,
                 image,
                 job,
                 entrydate,
                 create_time,
                 update_time
          from tb_emp
          where entrydate between '2000-01-01' and '2010-01-01';
      • IN operator
        • The specific code is as follows
        • -- 8.查询职位是2(讲师),3(学工主管),4(教研主管)的员工信息
          select id,
                 username,
                 password,
                 name,
                 gender,
                 image,
                 job,
                 entrydate,
                 create_time,
                 update_time
          from tb_emp
          where job in (2, 3, 4);
      • The LIKE operator (placeholder) fuzzy matching uses like (_ matches a single character, % matches a character)
        • The specific code is as follows
        • -- 9.查询姓名为两个字的员工信息
          select id,
                 username,
                 password,
                 name,
                 gender,
                 image,
                 job,
                 entrydate,
                 create_time,
                 update_time
          from tb_emp
          where name like '__';
      • IS NULL operator ( without =null )
        • The specific code is as follows
        • -- 3.查询没有分配职位的员工信息
          select id,
                 username,
                 password,
                 name,
                 gender,
                 image,
                 job,
                 entrydate,
                 create_time,
                 update_time
          from tb_emp
          where job is null;
        • -- 10.查询性‘张’的员工信息
          select id,
                 username,
                 password,
                 name,
                 gender,
                 image,
                 job,
                 entrydate,
                 create_time,
                 update_time
          from tb_emp
          where name like '张%';

      • IS NOT NULL operator ( and no !=null )
        • The specific code is as follows
        • -- 4.查询有职位的员工信息
          select id,
                 username,
                 password,
                 name,
                 gender,
                 image,
                 job,
                 entrydate,
                 create_time,
                 update_time
          from tb_emp
          where job is not null;
    • Logical Operators

      • AND/&& operator: used to satisfy multiple conditions at the same time.
        • The specific code is as follows
        • -- 7.查询入职日期在‘2000-0-01’(包含)到‘2010-01-01’(包含)之间且性别为女的员工信息
          select id,
                 username,
                 password,
                 name,
                 gender,
                 image,
                 job,
                 entrydate,
                 create_time,
                 update_time
          from tb_emp
          where entrydate between '2000-01-01' and '2010-01-01'
            and gender = 2;
          
      • OR/|| operator: used to meet any condition.
        • The specific code is as follows
        • -- 8.查询职位是2(讲师),3(学工主管),4(教研主管)的员工信息
          select id,
                 username,
                 password,
                 name,
                 gender,
                 image,
                 job,
                 entrydate,
                 create_time,
                 update_time
          from tb_emp
          where job = 2
             or 3
             or 4;
      • NOT/! Operator: Used to negate a condition.

Guess you like

Origin blog.csdn.net/weixin_64939936/article/details/131774716