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)
    
    
    
     
  • 相关阅读:
    C++预备知识
    C++求最小公倍数
    c++编写函数,递归删除字符串中的子串,求删除次数
    ERROR 1452 : Cannot add or update a child row: a foreign key constraint fails
    django快速搭建blog
    北邮 北理 人大经验
    C、C++、Java语言中异常处理机制浅析
    学习git部署
    各种符号的使用情况说明以及区别
    【转】通过fio工具,测试SATA,SAS,SSD 读写性能
  • 原文地址:https://www.cnblogs.com/mingerlcm/p/9891139.html
Copyright © 2011-2022 走看看