Consider a document that contains a list of professors (name, Id, department Id) and a separate list of classes taught (professor Id, course code, semester). Use aggregate functions of XQuery to produce the following documents:

a. A list of professors (name, Id) with the number of di?erent courses taught by each professor.
b. A list of departments (department Id) along with the number of di?erent courses ever taught by the professors in them. (The same course taught in di?erent semesters or a course taught in the same semester by di?erent professors is counted as one.)


a. Assume that the document consists of two elements, Professors and Classes, which in turn are lists of elements Professor and Class, respectively.



{
FOR $p IN
doc("http://xyz.edu/profs-courses.xml")//Professor
LET $courses := -- All courses ever taught by $p
distinct-values(
doc("http://xyz.edu/profs-courses.xml")
//Class[ProfId=$p/Id]/CrsCode
)
RETURN $p count($courses)
}



b.


{
LET $depts :=
distinct-values(doc("http://xyz.edu/profs-courses.xml")//DeptId)
FOR $d IN $depts
LET $courses := { -- All courses ever taught by $d
FOR $p IN doc("http://xyz.edu/profs-courses.xml")
//Professor[DeptId=$d/DeptId],
$c IN doc("http://xyz.edu/profs-courses.xml")
//Class[ProfId=$p/Id]/CrsCode
RETURN $c
}
RETURN $d count(distinct-values($courses))
}

Computer Science & Information Technology

You might also like to view...

MC Hostname______references the local machine.

a) myhost. b) localhost. c) thishost. d) None of the above.

Computer Science & Information Technology

Positive ____ come out of the page toward users, while negative values recede away from users.

A. z-values B. x-values C. y-values D. q-values

Computer Science & Information Technology

What would you use to mark the term to describe in a description list?

a. dl b. dt c. dd d. li e. None of the above.

Computer Science & Information Technology

In a peer-to-peer network, only the central host computer supplies the resources, the other computers request resources from this host.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology