create table student(
id int, -- id编号
name varchar(20), -- 姓名
chinese int, -- 语文
english int, -- 英语
math int -- 数学
);
insert into student(id,name,chinese,english,math) values(1,'行哥',89,78,90);
insert into student(id,name,chinese,english,math) values(2,'潘金莲',67,53,95);
insert into student(id,name,chinese,english,math) values(3,'凤姐',87,78,77);
insert into student(id,name,chinese,english,math) values(4,'旺财',88,98,92);
insert into student(id,name,chinese,english,math) values(5,'白小黑',82,84,67);
insert into student(id,name,chinese,english,math) values(6,'白小黄',55,85,45);
insert into student(id,name,chinese,english,math) values(7,'范蹦蹦',75,65,30);
1.查询表中所有学生的信息。
SELECT * FROM student;
2 查询表中所有学生的姓名和英语成绩。
SELECT NAME,english FROM student;
3 过滤表中重复数据。(去重的关键字 distinct)
SELECT DISTINCT chinese,english,math FROM student;
4.统计每个学生的总分
SELECT id,NAME,(chinese+english+math) '总成绩' FROM student;
5.在所有学生总分数上加10分特长分。
SELECT id,NAME,(chinese+english+math+10) '总成绩' FROM student;
6.使用别名表示学生分数。
SELECT id,NAME,chinese AS '语文',english AS '英语',math AS '数学' FROM student;
7.查询姓名为行哥的学生成绩
SELECT * FROM student WHERE NAME LIKE'行哥';
8.查询英语成绩大于90分的同学
SELECT * FROM student WHERE english >90;
9.查询总分大于200分的所有同学
SELECT * FROM student WHERE (chinese+english+math)>200;
10.查询英语分数在 80-90之间的同学。
SELECT * FROM student WHERE english BETWEEN 80 AND 90;
11.查询数学分数为89,90,91的同学。
SELECT * FROM student WHERE math =89 OR math =90 OR math =91;
12.查询所有姓白的学生英语成绩。
SELECT * FROM student WHERE NAME LIKE '白__';
13.查询数学分>80并且语文分>80的同学
SELECT * FROM student WHERE math>80 AND chinese>80;
14.查询英语>80或者总分>200的同学
SELECT * FROM student WHERE english>80 OR (chinese+english+math)>200;
15.对数学成绩升序排序
SELECT * FROM student ORDER BY math ASC;
16.对总分降序排序,然后再按数学从高到低的顺序输出
SELECT *,(chinese+english+math)'总成绩' FROM student ORDER BY (chinese+english+math)DESC,math DESC;
17.对姓白的学生成绩排序输出(排序规则自己定义)
SELECT * FROM student WHERE NAME LIKE '白__' ORDER BY math DESC;
18.查询数学成绩大于等于平均分的所有学生信息
SELECT * FROM student WHERE math>=(SELECT AVG(math));
19.查询出英语成绩最高分的学生信息
SELECT * FROM student WHERE english=(SELECT MAX(english) FROM student);
20.模糊查询出学生姓名中第二个字是金的学生信息
SELECT * FROM student WHERE NAME LIKE '_金_';
21.查询出英语成绩平均分是多少
SELECT AVG(english) '英语平均分' FROM student ;
22.查询出数学总分是多少
SELECT SUM(math) '数学总分' FROM student;
23.查询学生表中有多少条记录
SELECT COUNT(id) FROM student;