Xquery XML

File: Data.xml

  
  
  
  
  
  
  

File: Query.xquery
for $d in distinct-values(doc("Data.xml")//employee/@location)
let $employees := doc("Data.xml")//employee[@location = $d]
order by $d
return                    numemployees="{count($employees)}"
                   distinct="{count(distinct-values($employees/@yearServed))}"
                   total="{sum($employees/@yearServed)}"/>
Output: