【MySQL】DQL-条件查询语句全解(附带代码演示&案例练习)

前言

大家好吖,欢迎来到 YY 滴MySQL系列 ,热烈欢迎! 本章主要内容面向接触过C++ Linux的老铁
主要内容含:
在这里插入图片描述

欢迎订阅 YY滴C++专栏!更多干货持续更新!以下是传送门!

DQL基本介绍&语法&各种查询语句总览

  • DQL英文全称是Data Query Language(数据查询语言),数据查询语言,用来 查询 数据库中表的记录。
  • 查询关键字: SELECT
  • DQL-语法
    在这里插入图片描述

※数据准备工作(必看)

create table emp(

     id int comment  '编号 ',
     workno varchar(10) comment  '工号 ',
     name varchar(10) comment  '姓名 ',
     gender char(1) comment '性别' ,
     age tinyint unsigned comment '年龄',
     idcard char(18) comment‘身份证号’,
     entrydate date comment ‘入职时间’

)comment '员工表';

一.DQL-条件查询

语法&条件种类&可cv例题语句

  • 如下所示:
    在这里插入图片描述
--1.查询年龄等于88的员工
select * from emp where age = 88;

--2.查询年龄小于20的员工信息
select * from emp where age < 20;

--3.查询年龄小于等于20的员工信息
select * from emp where age <= 20;

--4.查询没有身份证号的员工信息
select * from emp where idcard is null;

--5.查询有身份证号的员工信息
select * from emp where idcard is not null;

--6.查询年龄不等于88的员工信息
select * from emp where age != 88;
select * from emp where age <> 88;

--7.查询年龄在15(包含)到20岁(包含)之间的员工信息
select * from emp where age >= 15 && age <= 20;
select * from emp where age >= 15 and age <= 20;
select * from emp where age between 15 and 20;

--8.查询性别为女且年龄小于25岁的员工信息
select * from emp where gender ='女'and age < 25;

--9.查询年龄等于182040的员工信息
select * from emp where age = 18 or age = 20 or age =40;
select * from emp where age in(18,20,40);

--10.查询姓名为两个字的员工信息_%
select * from emp where name like '__';

--11.查询身份证号最后一位是X的员工信息
select * from emp where idcard like '%x';
select * from emp where idcard like '_________________x';//_的数目是身份证数-1

相关推荐

  1. opencv期末练习题(7)附带

    2024-03-30 05:30:04       56 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-30 05:30:04       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-30 05:30:04       106 阅读
  3. 在Django里面运行非项目文件

    2024-03-30 05:30:04       87 阅读
  4. Python语言-面向对象

    2024-03-30 05:30:04       96 阅读

热门阅读

  1. ARMday1

    2024-03-30 05:30:04       39 阅读
  2. 数据挖掘篇【 alias方法 和 隐式转换 】

    2024-03-30 05:30:04       36 阅读
  3. sync包常用并发安全数据结构

    2024-03-30 05:30:04       39 阅读
  4. 解决dtypes.py:513: FutureWarning:...系列问题【TensorFlow】

    2024-03-30 05:30:04       210 阅读
  5. Redis--缓存常用的 3 种读写策略

    2024-03-30 05:30:04       38 阅读
  6. html目录

    2024-03-30 05:30:04       45 阅读
  7. PyTorch数据结构

    2024-03-30 05:30:04       34 阅读
  8. UniApp中获取安卓设备的唯一标识符

    2024-03-30 05:30:04       35 阅读
  9. MySQL 架构

    2024-03-30 05:30:04       39 阅读
  10. 大模型提示工程之Prompt框架和示例

    2024-03-30 05:30:04       44 阅读