zoukankan      html  css  js  c++  java
  • mysql 数据操作 单表查询 使用正则表达式查询

    SELECT * FROM employee WHERE name REGEXP '^ale';
    
    SELECT * FROM employee WHERE name REGEXP 'on$';
    
    SELECT * FROM employee WHERE name REGEXP 'm{2}';
    
    
    小结:对字符串匹配的方式
    WHERE name = 'egon';
    WHERE name LIKE 'yua%';
    WHERE name REGEXP 'on$';



    需求 找到name 为jin开头的记录

    regexp
    mysql> select * from employee where name regexp '^jin';
    +----+------------+--------+-----+------------+---------+--------------+----------+--------+-----------+
    | id | name       | sex    | age | hire_date  | post    | post_comment | salary   | office | depart_id |
    +----+------------+--------+-----+------------+---------+--------------+----------+--------+-----------+
    |  4 | jingliyang | female |  18 | 2011-02-11 | teacher | NULL         |  9000.00 |    401 |         1 |
    |  5 | jinxin     | male   |  18 | 1900-03-01 | teacher | NULL         | 30000.00 |    401 |         1 |
    +----+------------+--------+-----+------------+---------+--------------+----------+--------+-----------+
    2 rows in set (0.11 sec)
    
    
    

    小练习

    需求匹配所有员工中 name 为 jin开头  n或者g结尾的记录

    |或者
    () 包含多个
    $ 结尾
    mysql> select * from employee where name regexp '^jin.*(g|n)$';
    +----+------------+--------+-----+------------+---------+--------------+----------+--------+-----------+
    | id | name       | sex    | age | hire_date  | post    | post_comment | salary   | office | depart_id |
    +----+------------+--------+-----+------------+---------+--------------+----------+--------+-----------+
    |  4 | jingliyang | female |  18 | 2011-02-11 | teacher | NULL         |  9000.00 |    401 |         1 |
    |  5 | jinxin     | male   |  18 | 1900-03-01 | teacher | NULL         | 30000.00 |    401 |         1 |
    +----+------------+--------+-----+------------+---------+--------------+----------+--------+-----------+
    2 rows in set (0.00 sec)
    
    
    
     
  • 相关阅读:
    nginx使用https协议
    DUBBO入门
    Zookeeper学习笔记4
    maven dependency:tree中反斜杠的含义
    CATALINA_BASE与CATALINA_HOME的区别
    log4j打印抛出异常时堆栈内容
    如何获取e.printStackTrace()的内容
    springboot+RabbitMQ 问题 RabbitListener 动态队列名称:Attribute value must be constant
    详细介绍Spring Boot + RabbitMQ实现延迟队列
    springboot集成rabbitmq(实战)
  • 原文地址:https://www.cnblogs.com/mingerlcm/p/9891139.html
Copyright © 2011-2022 走看看