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)
    
    
    
     
  • 相关阅读:
    Django 数据库常用字段类型、选项参数、外键约束
    Django 项目基础配置
    MySQL连接列值
    SQL 限制查询结果
    python+appium+真机测试
    P3089 [USACO13NOV]POGO的牛Pogo-Cow
    P2889 [USACO07NOV]挤奶的时间Milking Time
    P2679 子串
    P3932 浮游大陆的68号岛
    P1514 引水入城
  • 原文地址:https://www.cnblogs.com/mingerlcm/p/9891139.html
Copyright © 2011-2022 走看看