Escolar Documentos
Profissional Documentos
Cultura Documentos
Q3. Find all areas in which courses are offered XQuery: ( version a ) q3a.xq
<result> { doc("university.xml")//course/area } </result>
Q6. Find all CS students who live in Edinburg XQuery: ( version a ) q6a.xq
<result> { for $s in doc("university.xml")//student where $s/major = "CS" and $s/address = "Edinburg" return $s/sid } </result>
Q7. Find all students whose majors are undeclared XQuery: ( version a ) q7a.xq
<result> { for $s in doc("university.xml")//student where not($s/major) return $s/sid } </result>
Q8. Find titles of all graduate courses (cid is 6000 or higher) in the DB area XQuery: ( version a ) q8a.xq
<result> { for $c in doc("university.xml")//courses/course where $c/area = "DB" and $c/cid >= 6000 return $c/title } </result>
Q9. Find all course identifiers and show (rename) them as course numbers XQuery:
<result> { for $c in doc("university.xml")//courses/course return <CourseNumber>{data($c/cid)}</CourseNumber> } </result>
Q10. Find all course identifiers with their respective course areas and show (rename) them as course numbers and groups XQuery:
<result> { for $c in doc("university.xml")//courses/course let $cn := <CourseNumber>{data($c/cid)}</CourseNumber> let $cg := <CourseGroup>{data($c/area)}</CourseGroup> let $out := ($cn,$cg) return <row>{$out}</row> } </result>
Q11. Find all possible pairs (combinations) of students and professors XQuery:
<result> { for $s in doc("university.xml")//students/student, $p in doc("university.xml")//professors/professor return <row>{($s/sid,$p/pid)}</row> } </result>
Q13. Find identifiers of all courses that the student with name Nathan took XQuery:
<result> { for $s in doc("university.xml")//students/student[name = "Nathan"], $t in doc("university.xml")//transcripts/record where $s/sid = $t/sid return $t/cid } </result>
Q14. Find titles of all courses that the student with name Nathan took XQuery:
<result> { for $s in doc("university.xml")//students/student[name = "Nathan"], $t in doc("university.xml")//transcripts/record, $c in doc("university.xml")//courses/course where $s/sid = $t/sid and $t/cid = $c/cid return $c/title } </result>
Q15. Find course titles and professor names for courses that the student with name Nathan took XQuery:
<result> { for $s in doc("university.xml")//students/student[name = "Nathan"], $t in doc("university.xml")//transcripts/record, $c in doc("university.xml")//courses/course, $p in doc("university.xml")//professors/professor where $s/sid = $t/sid and $t/cid = $c/cid and $t/pid = $p/pid return <row>{($c/title, $p/name)}</row> } </result>
Q16. Find names of students who took a course with professor Artem XQuery: ( version a ) q16a.xq
<result> { for $s in doc("university.xml")//students/student, $t in doc("university.xml")//transcripts/record, $p in doc("university.xml")//professors/professor where $s/sid = $t/sid and $t/pid = $p/pid and $p/name = "Artem" return $s/name } </result>
Q21. Find names of professors who taught INTRO or DB courses XQuery: ( version a ) q21a.xq
<result> { (for $p in doc("university.xml")//professors/professor, $t in doc("university.xml")//transcripts/record, $c in doc("university.xml")//courses/course where $p/pid = $t/pid and $t/cid = $c/cid and $c/area = "INTRO" return $p/name) union (for $p in doc("university.xml")//professors/professor, $t in doc("university.xml")//transcripts/record, $c in doc("university.xml")//courses/course where $p/pid = $t/pid and $t/cid = $c/cid and $c/area = "DB" return $p/name) } </result>
Result:
<result> <name>Artem</name> <name>John</name> <name>Christine</name> </result>
Q23. Find names of professors who taught both INTRO and DB courses XQuery:
<result> { (for $p in doc("university.xml")//professors/professor, $t in doc("university.xml")//transcripts/record, $c in doc("university.xml")//courses/course where $p/pid = $t/pid and $t/cid = $c/cid and $c/area = "INTRO" return $p/name) intersect (for $p in doc("university.xml")//professors/professor, $t in doc("university.xml")//transcripts/record, $c in doc("university.xml")//courses/course where $p/pid = $t/pid and $t/cid = $c/cid and $c/area = "DB" return $p/name) } </result>
Q24. Find names of professors who taught in both 2009 and 2010 XQuery:
<result> { (for $p in doc("university.xml")//professors/professor, $t in doc("university.xml")//transcripts/record where $p/pid = $t/pid and $t/year = "2009" return $p/name) intersect (for $p in doc("university.xml")//professors/professor, $t in doc("university.xml")//transcripts/record where $p/pid = $t/pid and $t/year = "2010" return $p/name) } </result>
Q28. Find courses that were not offered in Fall 2009 XQuery:
<result> { let $c := (doc("university.xml")//courses/course) except (for $t in doc("university.xml")//transcripts/record, $c in doc("university.xml")//courses/course where $t/cid = $c/cid and $t/year = "2009" return $c) return $c/cid } </result>
Q30. Find names of students who took every course in the INTRO area XQuery:
<result> { for $s in doc("university.xml")//students/student let $courses := doc("university.xml")//courses/course[area = "INTRO"], $transcripts := doc("university.xml")//transcripts/record[sid = $s/sid] where every $c in $courses satisfies some $t in $transcripts satisfies $t/cid = $c/cid return $s/name } </result>
Q32. Find professors who taught at least two (>=2) different courses XQuery: ( version a ) q32a.xq
<result> { for $t1 in doc("university.xml")//transcripts/record, $t2 in doc("university.xml")//transcripts/record where $t1/pid = $t2/pid and $t1/cid != $t2/cid return $t1/pid } </result>
Q35. Find the total number of courses offered in Fall 2009 XQuery: ( version a ) q35a.xq
<result> { let $crs := doc("university.xml")//transcripts/record[semester = "Fall" and year = "2009"] return count($crs) } </result>
Q37. Find the total number of credits completed by student with id 101 XQuery:
<result> { sum( for $r in doc("university.xml")//transcripts/record[sid = "101"], $c in doc("university.xml")//courses/course where $r/cid = $c/cid return $c/credits ) } </result>