Description

OQL

XQuery

Result

List the departments and the number of employees in each department

Select D. Name, headCount: count (select E.employeeid from Employee E

where E.worksin = D. departmentId) from Departments D, dept. has emp group by Name: D. Name;

for $dept in //Department

let $headCount:= count(//Employee[worksin=$dept/ departmentId])

return

{$deptartment/Name} {$headCount}

Accounting 2

Administration 3

Finance 2

Find the names of all employees in Accounting

Select

Employee

JOIN Department ON Employee. worksin = Department.departmentId

WHERE Department.Name =’ Accounting’

let $dept: = //Department [Name ='Accounting']/departmentId

return//Employee[worksin = $dept]/empName

Smith

Scott