DQL语句

发布时间 2023-07-10 22:01:42作者: harper886

DQL语句

DQL数据库查询语言

image-20230706203638034

查询关键字:SELECT

image-20230706203916144

DQL基本查询

image-20230706210629396

  1. 查询指定字段 name ,workno ,gae返回
select name,workno ,age from emp;
  1. 查询所有字段并且返回

    select *from emp;
    

    或者

    select id, workno, name, gender, age, idcard, workaddress, entrydate from emp;
    

    建议不要写✳号进行查询

    1. 查询所有员工的工作地址,起别名
    select workaddress as '工作地址' from emp;
    

    as可以省略

select workaddress '工作地址' from emp;

  1. 查询公司员工的上班地址(不要重复)

    select distinct workaddress '工作地址' from emp;
    

    DQL条件查询

可以使用比较运算符和逻辑运算符

image-20230710213219565

1. 查询年龄等于88的员工

select *from emp where age=88;

2. 查询年龄小于20岁的员工

select *from emp where age<20;

3.查询年龄小于20岁的员工

select *from emp where age<=20;
  1. 查询没有身份证号的员工
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 between 15 and 20;
select *from emp where age >=15 and age<=20;
select *from emp where age >=15 && age<=20;

8,查询性别为女且年龄小于25岁的员工信息

select *from emp where age<25 and gender='女';

9.查询年龄等于18或20或40的员工信息

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';