zoukankan      html  css  js  c++  java
  • mysql_where条件

    where字句中可以使用:

    1. 比较运算符:> < >= <= <> !=
    2. between 80 and 100 值在10到20之间
    3. in(80,90,100) 值是10或20或30
    4. like 'egon%'
        pattern可以是%或_,
        %表示任意多字符
        _表示一个字符
    5. 逻辑运算符:在多个条件直接可以使用逻辑运算符 and or not

    1.但条件查询

    # 查询id大于7的记录。
    select * from employee where id > 7

    2.多条件查询

    # 查询post为'teacher' 并且 salary 大于8000的记录。
    select * from employee where post = 'teacher' and salary > 8000;

    3.关键字between and

    # 查询salary大于等于20000和salary小于等于30000的记录。
    select * from employee where salary between 20000 and 30000;

    4.in

    # 查询age为73或81或28的记录。
    select * from employee where age in (73,81,28);

    5.判断记录是否为NULL

    # 查询post_comment字段为null的记录。
    select * from employee where post_comment is null;
    # 查询post_comment字段不为null的记录。
    select * from employee where post_comment is not null;

    6.like(%:匹配任意多个字符。_:匹配任意一个字符)

    # 查询name字段为"jin"开头的记录。
    select * from employee where name like 'jin%';
    # 查询name字段为"ao"结尾的记录。
    select * from employee where name like '%ao';
    # 查询name字段为"jin"开头后面有任意3个字符的记录。
    select * from employee where name like 'jin___';

     7.正则表达式

    # 查询name字段以al开头的记录。
    SELECT * FROM employee WHERE name REGEXP '^al';
  • 相关阅读:
    CentOS挂载ntfs
    搬水果
    CentOS安装完显卡启动进不去系统
    二叉树遍历
    拓展的异常类
    Visual Studio 2008 IDE 出现 “帮助更新正在进行”错误的解决办法
    JSON工具SuperObject编译时"整数溢出"异常的解决办法
    引用命名区域
    ruby操作excel的几段代码
    Delphi2009&2007中,测试工程的初级使用(DUnit)
  • 原文地址:https://www.cnblogs.com/wangdianchao/p/12259529.html
Copyright © 2011-2022 走看看