DML 高级查询

模糊查询 like;

select id,name from info where name like '张'; #查询info表里面姓张的人 

select i.name,s.grade from student i inner join score s on i.id=s,sid where name like '刘%'; #查询所有姓刘的学生成绩

模糊查询 is null

select name,grade from score where grade is null; #查询score表中成绩为空的人

模糊查询 between

select age,name from student where between 18 and 22;  #查询student表中年龄为18-22岁的人

数据查询排序 order by 

1.按单列排序 

select id,grade from score order by grade desc;   #单列排序  将score表中的成绩从高到低排序

2.按多列排序

select id,grade from score order by grade,id asc;    #多列排序   将score表中的成绩从低到高进行排序,成绩相同的按照id排序

分组查询  group by  (主要是配合聚合函数使用)

select id,sum(grade) from score group by grade  having max(grade)>300;   #查询总成绩大于300的人

EXISTS 子查询

select distinct grade from score where exitst (select 1 from score where grade>60)  order by  grade limit 3;

采用EXISTS检测是否有人考试成绩达到60分以上,如果有,使用SELECT语句按成绩从高到低排序,显示前3名学员学号和成绩

NOT EXISTS 子查询

select age from student a where not exists (select 1 from student b where a.age<b.age);   #求最大年龄   

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值