• Mysql常用sql语句(8)- where 条件查询


    测试必备的Mysql常用sql语句系列

    https://www.cnblogs.com/poloyy/category/1683347.html

    前言

    • 条件查询应该是作为测试平时用到最多的关键字了!!
    • 它可以用来指定查询条件,减少不必要的查询时间

    where的语法格式

    WHERE 查询条件

    五种查询条件

    1. 比较运算符、逻辑运算符
    2. between and 关键字
    3. is null 关键字
    4. in、exist 关键字
    5. like 关键字

    本篇只讲比较运算符、逻辑运算符,其他会在后面篇幅讲解哦

    有哪些比较运算法?

    • =:等于
    • <=>:安全等于
    • !=、<>:不等于
    • <、>、<=、>=:小于、大于、小于等于、大于等于

    有哪些逻辑运算符?

    • and、&&:所有查询条件均满足才会被查询出来
    • or、||:满足任意一个查询条件就会被查询出来
    • xor:满足其中一个条件,并且不满足另一个条件时,才会被查询出来

    这里有个重点,当运算符混合使用时,需要关注它们的优先级,具体可参考这篇博文:(后面补充)

    单一条件的查询栗子

    一般单一条件查询用的就是比较运算符

    select * from yyTest where id = 1;
    select * from yyTest where id != 1;
    select * from yyTest where height > 170;
    select * from yyTest where height >= 175;
    select * from yyTest where age < 20;
    select * from yyTest where age <= 20;

    多条件的查询栗子

    多条件的查询都需要使用逻辑运算符,下面的栗子比较简单不展开描述

    select * from yyTest where sex = 1 and height >175;
    select * from yyTest where sex = 1 && height >175;
    select * from yyTest where height < 165 or height >175;
    select * from yyTest where height < 165 || height >175;

    查询 age 小于 21,并且 height 小于 165 的学生信息和 age 大于 21,并且 height 小于等于 165 的记录

    • 满足age< 21 但 不满足height >=165
    • 不满足age<121 但 满足height >=165
    select * from yyTest where age < 21 xor height >= 165;
  • 相关阅读:
    Django学习笔记之model篇(二)
    Django学习笔记之model篇(一)
    Django学习笔记之auth系统
    rust中文论坛
    cookies和session总结
    golang 简书
    mac快捷键
    目前的缺点
    Phalcon notes
    Docker note
  • 原文地址:https://www.cnblogs.com/poloyy/p/12859861.html
Copyright © 2020-2023  润新知