我无法弄清楚如何为学生运行查询

编程入门 行业动态 更新时间:2024-10-25 21:30:38
本文介绍了我无法弄清楚如何为学生运行查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这是我为每个表创建的代码,不确定如何连接表来计算 gpa??

Here is my code that I created for each of the tables, not sure how to join the tables to calculated the gpa's??

CREATE TABLE Student(SSN NUMBER(4) NOT NULL, SName VARCHAR(20) NOT NULL, Major VARCHAR(4),

推荐答案

因为grade和SSN在成绩表中,所以不需要加入就可以得到平均成绩如下:

Because grade and SSN are in the grades table, you dont need to join and can get the average grade like this:

这给出了每个学生的平均成绩,按成绩排序:

This gives the average grade per student, ordered by the grade:

SELECT AVG(g.Grade), g.SSN FROM Grade g group by g.SSN order by AVG(g.Grade)

如果您希望每门课程的平均成绩如下所示:

If you wanted average grade per course it would look like this:

SELECT AVG(g.Grade), go FROM Grade g group by go order by AVG(g.Grade)

但是,如果您需要来自学生的更多信息,则需要加入学生表:

However, if you need more information from student, you'd need to join to the student table:

select * from ( SELECT AVG(g.Grade) as average_grade, g.SSN FROM Grade g group by g.SSN) a inner join Student s on a.ssn = s.ssn

更多推荐

我无法弄清楚如何为学生运行查询

本文发布于:2023-11-27 02:56:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636276.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:弄清楚   学生

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!