今日做的是小练习~
题目:
有两张表,第一张表为Cust(学号studentno、学生名字name、学生住址address、电话号码telno),第二张表Mark(学号studentno、英语成绩english、数学成绩math、计算机成绩computer)
1.请写出计算所有学生的英语平均成绩的sql语句
答:select avg(english) from Mark;
2.现有五个学生,其学号假定分别为11,22,33,44,55;请用一条SQL语句实现列出这五个学生的数学成绩及其姓名、学生地址、电话号码;
答:select C.Name,C.Address,C.Telno,M.math from Cust C join Mark M on C.studentno = M.studentno where C.studentno in(11,22,33,44,55);
3. 查询所有学生的姓名、计算机成绩,按照计算机成绩从高到低排序;
答:select C.Name, M.computer from Cust C join Mark M on C.studentno = M.studentno order by computer desc;
4.查询所有总成绩大于240分的学生学号、姓名、总成绩,按照总成绩从高到低排序;
答:select C.studentno, C.Name,(M.english+M.math+M.computer) total from Cust C join Mark M on C.studentno = M.studentno having total>240 order by total desc;