MySQL练习题(1)

1,创建如下学生表
mysql> create table student(
-> id int,
-> name varchar(20),
-> gender varchar(20),
-> chinese int,
-> math int,
-> english int
-> );
插入如图数据
在这里插入图片描述

1-- 查询表中所有学生的信息
select *from student;

在这里插入图片描述

2-- 查询表中所有学生的姓名和英语成绩
select name,english from student;

在这里插入图片描述

3-- 过滤表中的重复数据
select distinct id,name,gender,chinese,math,english from student;

在这里插入图片描述

4-- 统计每个学生的总分
 select name ,chinese+math+english num from student;

在这里插入图片描述

5-- 所有学生总分上加上10
select name ,chinese+math+english+10 num from student;

在这里插入图片描述

6-- 使用别名表示学生分数
select name ,chinese as "语文",math as "数学",english as "英语" from student;

在这里插入图片描述

7-- 查询英语成绩大于90分的所有同学
select name ,english from student where english >90;

在这里插入图片描述

8-- 查询总分大于200分的所有同学
select name,chinese+math+english num from student where chinese+math+english>200;
+--------+------+

| name | num |
±-------±-----+
| 张明 | 257 |
| 李进 | 215 |
| 王五 | 242 |
| 李一 | 278 |
| 李财 | 233 |
±-------±-----+

9-- 查询英语成绩在80到90之间的所有同学
select name ,english from student where 80<english and english<90;

在这里插入图片描述

10-- 查询英语成绩不在80到90之间的所有同学
select name ,english from student where english<80 or english>90;
+--------+---------+

| name | english |
±-------±--------+
| 李进 | 95 |
| 王五 | 77 |
| 李一 | 92 |
| 李财 | 67 |
| 张宝 | 45 |
| 黄蓉 | 30 |
| 黄蓉 | 30 |
±-------±--------+

11-- 查询数学分数为89,90,91的同学
select name ,english from student where math in(89,90,91);
显示Empty set (0.00 sec)

12-- 查询数学分数不为89,90,91的同学
select name ,english from student where math  not in(89,90,91);
+--------+---------+

| name | english |
±-------±--------+
| 张明 | 90 |
| 李进 | 95 |
| 王五 | 77 |
| 李一 | 92 |
| 李财 | 67 |
| 张宝 | 45 |
| 黄蓉 | 30 |
| 黄蓉 | 30 |
±-------±--------+

13-- 查询所有姓李的学生英语成绩
select name ,english from student where  name like '李%';
+--------+---------+

| name | english |
±-------±--------+
| 李进 | 95 |
| 李一 | 92 |
| 李财 | 67 |
±-------±--------+

14-- 查询数学分80且语文80分的同学
select name ,chinese, math from student where chinese >80 and  math >80;

±-------±--------±-----+
| name | chinese | math |
±-------±--------±-----+
| 李一 | 88 | 98 |
| 李财 | 82 | 84 |
±-------±--------±-----+

15-- 查询英语80或者总分200的同学
select name ,chinese+math+english num from student where english >80 or chinese+math+english  >200;
+--------+------+

| name | num |
±-------±-----+
| 张明 | 257 |
| 李进 | 215 |
| 王五 | 242 |
| 李一 | 278 |
| 李财 | 233 |
±-------±-----+

16-- 对学生数学成绩进行降序排序后输出
 select name,math from student  order by math desc;
 +--------+------+

| name | math |
±-------±-----+
| 李一 | 98 |
| 张宝 | 85 |
| 李财 | 84 |
| 张明 | 78 |
| 王五 | 78 |
| 黄蓉 | 65 |
| 黄蓉 | 65 |
| 李进 | 53 |
±-------±-----+
8 rows in set (0.00 sec)

17-- 对总分从高到低的顺序输出
select name ,math+chinese+english num from student order by num;
+--------+------+

| name | num |
±-------±-----+
| 黄蓉 | 170 |
| 黄蓉 | 170 |
| 张宝 | 185 |
| 李进 | 215 |
| 李财 | 233 |
| 王五 | 242 |
| 张明 | 257 |
| 李一 | 278 |
±-------±-----+

18-- 对姓李的学生按总成绩升序排序输出
select name ,english+math+chinese num from student where  name like '李%'order by num;
+--------+------+

| name | num |
±-------±-----+
| 李进 | 215 |
| 李财 | 233 |
| 李一 | 278 |
±-------±-----+

19-- 查询男生和女生分别有多少人,并将人数降序输出
 select gender,count(*) from student group by gender order by gender de;sc;
 +--------+----------+

| gender | count(*) |
±-------±---------+
| 男 | 4 |
| 女 | 4 |
±-------±---------+

20-- 查询男生和女生分别有多少人,并将人数降序输出,并查询出大于9的性别人数信息
 select gender,count(*) from student group by gender order by gender de;sc;
 +--------+----------+

| gender | count(*) |
±-------±---------+
| 男 | 4 |
| 女 | 4 |
±-------±---------+

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值