Analyze Data

The following queries use the Mondial database, a data set compiled by the Universität Göttingen.

For each country, list the 3 cities with the highest population

(: This script accesses the mondial database, which can be found at :) for $country in /mondial/country let $cities := (for $city in $country//city[population] order by xs:integer($city/population[1]) descending return $city) order by $country/name return <country name="{$country/name}"> { subsequence($cities, 1, 3) } </country>

Find all Spanish provinces and their cities

xquery version "1.0"; let $country := /mondial/country[name = 'Spain'] for $province in $country/province order by $province/name return <province> {$province/name} { for $city in $country//city[@province=$province/@id] order by $city/name return $city } </province>

Find the countries with the largest Roman Catholic population

for $country in /mondial/country where some $r in $country/religions satisfies $r = "Roman Catholic" order by $country/religions[. = "Roman Catholic"]/@percentage cast as xs:double descending return <country name="{$country/name}"> {$country/religions} </country>