【发布时间】:2014-11-07 20:39:10
【问题描述】:
所以我在让 avg 函数在 XQuery 中按我想要的方式工作时遇到了一些麻烦。我有一个具有 GPA 和分类(大一、大二、大三、大四)的学生的 XML 文件。我想找到每个分类的平均 GPA。我首先得到不同的分类。然后,我得到所有学生的列表,并在学生分类 = 不同分类时选择平均 GPA。这将返回 4 个平均 GPA(我想要的),但它们都是相同的。我已经解决这个小问题好几个小时了,希望能够继续完成我的任务,但这给我带来了太多麻烦。代码如下:
<T> {
for $dc in distinct-values(doc("ComS363/UniversityDatasets/Student.xml")/Students/Student/Classification)
let $student := doc("ComS363/UniversityDatasets/Student.xml")/Students/Student
let $aveGPA := avg($student/GPA)
where $student/Classification = $dc
return
<Classification>{$aveGPA}</Classification>
} </T>;
我的学生表设置如下:
<Students>
<Student>
<StudentID>118784412</StudentID>
<Classification>Sophomore</Classification>
<GPA>3.19</GPA>
<MentorID>201586985</MentorID>
<CreditHours>39</CreditHours>
</Student>
.
.
.
.
</Students>
那么你们知道为什么我在这里没有获得唯一的平均 GPA 用于分类吗? 提前感谢您的帮助。
【问题讨论】: