数据库sql语言第二节(数据查询语言DQL)

数据查询语言DQL

查询 select

1.查询所有列

*代表了所有

select * from 表名;
2.指定列查询
select 字段1,字段2,字段3.... from 表名;
3.条件查询(指定某一行查询)
select 字段1,字段2,字段3.... from 表名 where id=1;

select * from 表名 where id = 1;
  • 精确查询

    (1)查询名字是lucy的学生

select * from 表名 where name='lucy';

​ (2)查询名字是lucy并且性别是女的数据

select * from 表名 where name='lucy' and sex='女' and .....

​ (3)查询名字是lucy或者名字是alice

select * from 表名 where name='lucy' or name='alice' or .....
  • 模糊查询

    有时候我们输入的条件是一个很模糊的词语,这个时候我们需要模糊查询

    like 关键字

    %代表的是一个字符或者多个字符,_代表一个字符

例: %风% 关键字中 出现有 “风” 词语

​ _风% 关键字第二个字是 “风” 词语

​ %_风% 关键字第二个或者第三个以上出现了 “风” 词语

(1)查询名字中字母带有 “ l ” 学生

select * from emp where name like '%l%' ;

(2)查询名字中第二个字母是 “ l ” 的学生

select * from emp where name like '_l%' ;
  • 在 where 中使用 in
select * from 表名 where name in ('lucy','alice')
  • 判断是否为空
select * from 表名 where mobile is null;
select * from 表名 where mobile is not null;
  • 算术表达式

    加 减 乘 除, 取模(求余)

select 薪资*12 from yg;
  • 将指定结果排序(升序,降序)

order by 排序

asc 升序 desc 降序

null是最大值

(1)将员工薪资按照升序排序

select * from yg order by 薪资 asc

(2)将员工薪资按照降序排序

select * from yg order by 薪资 desc;
  • 去重distinct

    去掉重复的数据

    查询出哪些部门

select distinct dep from yg;

​ 查询部门个数 count() 统计函数

select count(distinct dep) as 部门数 from yg;

关键字

  • from 从哪一张表操作
  • insert into 插入
  • update … set 更新
  • delete 删除
  • where 条件
  • select 查询
  • and 并且
  • or 或者
  • where in 等价于 and
  • like 模糊查询 % 多个或者一个字符 _ 一个字符
  • order by 排序
  • asc 升序
  • desc 降序
  • distinct 去重
  • count() 统计函数
  • is null 空值
  • is not null 非空
  • as 给字段起别名
  • values 给定数据值
  • to_date(‘日期’,‘yyyy-mm-dd’) 添加日期
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值