高级查询一.1

在这里插入图片描述
高级查询一.1
一、分组查询
#分组查询
select id,AVG(grade) from score group by id;
#多列分组查询
select id,grade,AVG(grade) from score group by id,grade;
#查询补考的学生(多个)
select sid,AVG(grade) from score group by sid having COUNT(sid)>1;
二、子查询
#查询年龄比姓‘zhao’还大的人
select username from info where age>(select age from info where username=‘zhao’);
#查询成绩为80分的人
select i.username,s.grade from info i inner join score s on s.sid=i.id where s.grade=80;
select username from info where id=(select sid from score where grade=80);
三、in exists 子查询
#in子查询,可以返回多条记录
select username from info where id in(select sid from score where grade>=80);
#not in子查询
select username from info where id not in(select sid from score where grade>=80);
#exists查出来或者不出来都有结果
select id,grade from score where exists(select grade from score where grade>95) limit 0,5;
select id,grade from score where not exists(select grade from score where grade>95) limit 0,5;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值