数据库还没有开始学习,也算是第一次上课,根据老师讲的内容把能操作来的命令进行了整理,之后的学习进程中再进行更正延伸
3.查询 student 表的所有记录
SELECT * FROM student
4.查询 student 表的第 2 条到 4 条记录
SELECT * FROM student LIMIT 2,4;
5.从 student 表查询所有学生的学号(id)、姓名(name)和院系(department)的信息
SELECT id,name,department FROM student
6.从 student 表中查询计算机系和英语系的学生的信息
SELECT * FROM student
where(department ='计算机系' and department ='英语系')
7.从 student 表中查询年龄 28~32 岁的学生信息
SELECT * FROM student
where(age > 28 and age < 30)
8.从 student 表中查询每个院系有多少人
SELECT *FROME student
巩固练习:查询score表学习每个课程的人数
9.从 score 表中查询每个科目的最高分
select s1.name,s2.subject,s3.score from score table s1 join (select subject ,max(score) score from scorestable group by subject ) s2 on s1.subject=s2.subject and s1.score=s3.score
10.查询李四的考试科目(c_name)和考试成绩(grade)
SELECT c_name,grade FROME score name='李四'
11.用连接的方式查询所有学生的信息和考试信息
SELECT * FROME student,score
12.计算每个学生的总成绩
select name,sum(case when category='计算机' then score else 0 end) as '计算机',
sum(case when category='中文' then score else 0 end) as '中文',
sum(case when category='英语' then score else 0 end) as '英语',
sum(score) as '总分'
13.计算每个考试科目的平均成绩
14.查询计算机成绩低于 95 的学生信息
SELECT * FROM score
where(grade < 95 and c_name='计算机')
15.查询同时参加计算机和英语考试的学生的信息
16.将计算机考试成绩按从高到低进行排序
select * from score order by grade='计算机';
17.从 student 表和 score 表中查询出学生的学号,然后合并查询结果
18.查询姓张或者姓王的同学的姓名、院系和考试科目及成绩
19.查询都是湖南的学生的姓名、年龄、院系和考试科目及成绩