2

Using Enrollment.xml and Person.xml documents, I'm trying to list the names of students who have all A's. The ID field in Person refers to the StudentID field in Enrollment. There is an entry in enrollment for every class that a person is enrolled in (not one entry per student)

I can't seem to figure out how to write the query

Enrollment.xml form- >

<Document>
  <Table>
    <StudentID>170815037</StudentID>
    <Grade>C</Grade>
  </Table>
  <Table>
    <StudentID>193847547</StudentID>
    <Grade>A</Grade>
  </Table>
</Document>

Person.xml form - >

<Document>
  <Table>
    <Name>Wee Fletcher</Name>
    <ID>115423723</ID>
  </Table>
</Document>

Heres is what im trying working on, and i cant get it to work

for $a in doc("proj3/Person.xml")/Document/Table/ID
where every $s in doc("proj3/Enrollment.xml")//Table[StudentID = $a]
          satisfies ($s/Grade = "A")
    return $a/Name;
0

1 Answer 1

2

There's a minor problem: You set $a to doc("proj3/Person.xml")/Document/Table/ID, and later access $a/Name (which returns non-existant .../Table/ID/Name).

Change the assignment in your first line and the comparison in second (add /ID here) and your code will be fine:

for $a in doc("proj3/Person.xml")/Document/Table
where every $s in doc("proj3/Enrollment.xml")//Table[StudentID = $a/ID]
          satisfies ($s/Grade = "A")
    return $a/Name;
Sign up to request clarification or add additional context in comments.

7 Comments

i've added the homework tag, and posted what i have so far. any comments?
Try either "where any" (think that's the only problem in your statement) or the join pattern I provided. Probably using join-pattern will lead to better optimization in query compilers as it is more general.
wouldn't "where any" list students that have one or more A's? My query is looking for students that have ALL A's.
You're totally right, misread that. Will change my answer in a minute, found your problem.
My solution works except for one problem. There are people in the Person table that aren't students, such as Instructors and Mentors. These people are getting returned as well, even though they do NOT appear in the enrollment table.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.