查询练习1到10

1、查询 student表中的所有行

select *from student;

2、查询student 表中的name、class字段的所有行

select name,class from student;

3、查询teacher表中不重复的department 列;

select distinct department from teacher;

注意distinct:去重复的意思
4、查询 score 表中 成绩在60~80的所有行(两种方法)

select * from score where degree between 60 and 80;

其中between 。。。 and。。。 表示查询区间
②利用了逻辑运算符

select *from score where degree>60 and degree <80;

5、查询score 表中成绩为85,86或者88的行
这里用到in这个字符,in:查询多个数据

select *from score where degree in(85,86,88);

6、查询student 表中’95031‘班中或者性别为’女’的所有行
or表示或者的关系

select *from student where class ='90531' or sex='女';

7、以class降序查询student表中所有的记录
desc 降序 从高到底,asc :升序,从低到高

select *from student order by class desc;
select *from student order by class asc;

8、以 c_no 升序、degree 降序查询 score 表的所有行

select *from score order by c_no asc,degree desc;

9、.查询’95031’班的学生人数
count:统计

select  count(*from student where class=95031';

10、查询 score 表中的最高分的学生学号和课程编号(子查询或排序查询)。
子查询算出最高分
select max(degree) from score;

select s_no,c_no from score where degree=(select max(degree) from score);

排序查询

select s_no,c_no,degree from score order by degree desc limit 0,1;

limit 0,1 中0表示从第1个开始记录,1表示记录个数为1个;

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值