首页 > 其他分享 >DQL基础查询/条件查询

DQL基础查询/条件查询

时间:2023-02-27 20:22:39浏览次数:29  
标签:20 -- age 查询 stu 条件 DQL where select

基础查询:

  select name,age from stu;     -- 查两列

  select * from stu;        -- 查全部,不推荐

  select distinct address from stu;  --查一列去除重复数据

  select name,math as 数学成绩,english as 英语成绩 from stu;  -- 给列起别名

  select name,math 数学成绩,english 英语成绩 from stu;   --as可以省略

条件查询:

  大于/小于:

  select * from stu where age>20;    -- 大于20

  大于等于/小于等于:

  select * from stu where age>=20;    -- 大于等于20

  等于:

  select * from stu where age=20;    -- 等于20,注意是一个等号

  不等于:

  select * from stu where age!=20;      -- 不等于20

  select * from stu where age<>20;      -- 不等于20,<>和!=作用相同

  与:

  select * from stu where age>=20 && age<=30;  -- 大于等于20并且小于等于30

  select * from stu where age>=20 and age<=30;  -- &&与and作用一样

    特例:between ...and...:

    select * from stu where age between 20 and 30;     -- between...and...与&&与and作用一样

  或:

  select *from stu where age=10 or age=20 or age=30;

    特例:in

    select *from stu where age in (10,20,30)

  null:

  select *from stu where english is null;  -- 查空数据

  select *from stu where english is not null;  -- 查不为空的数据

  

标签:20,--,age,查询,stu,条件,DQL,where,select
From: https://www.cnblogs.com/dahuilang21/p/17161731.html

相关文章

  • Linux操作系统下查询NVMe盘符、Slot ID和Bus ID的对应关系
    在拆卸NVMePCIe固态硬盘时,需要查询Linux操作系统下NVMe盘符、SlotID和BusID的对应关系。操作步骤打开操作系统命令终端。依次执行cd/sys/bus/pci/slots和ll命令,找到......
  • mysql开启慢查询日志
    前言:mysql数据库默认没有开启慢查询日志,需要我们手动去设置这个参数;慢查询,它的主要作用是定位那些执行时间比较长的sql语句,运行时间超过long_query_time值的SQL(long_query_......
  • mysql查询近N天的数据
    今天select*from表名whereto_days(时间字段名)=to_days(now());昨天SELECT*FROM表名WHERETO_DAYS(NOW())-TO_DAYS(时间字段名)<=17天SELECT*F......
  • MySQL根据经纬度和距离查询最近的数据
    [lat]:输入的纬度[lon]:输入的经度[distance]:查询距离内的数据,单位mSELECT*FROM(SELECTidlon,lat......
  • springboot条件注册Condition注解
    环境识别importorg.springframework.context.annotation.Condition;importorg.springframework.context.annotation.ConditionContext;importorg.springframework.c......
  • 02 条件
    #2、什么是条件?什么可以当做条件?为何要要用条件?#第一大类:显式布尔值#2.1条件可以是:比较运算符#age=18#print(age>16)#条件判断之后会得到一个布尔值#2.1条......
  • db2 模糊查询
    今天在书写接口的时候遇到一个问题,查询接口需要模糊查询,我在百度上搜索mybatils的模糊查询不行,最后发现,mysql的模糊查询concat方法和db2的不一样。然后就找到领一种方法,使......
  • SQL SERVER 生僻字查询问题和关键字COLLATE
       先说问题,生僻字查询的问题,有的时候我们的数据里包含一些生僻字,在查询用Like模糊匹配的时候,发现有的查询不准确,测试数据如下:1--测试数据2ifnotobject_id(N'......
  • ELK kibana查询与过滤
    在kibana中,可通过搜索查询过滤事务或者在visualization界面点击元素过滤。创建查询在Discover界面的搜索栏输入要查询的字段。查询语法是基于Lucene的查询语法。允许布尔......
  • mybatis-关联查询3-自关联查询
      一对多的方式处理查询指定栏目的所有子孙栏目    查询指定栏目及其所有子孙栏目 多对 一的方式处理   ......