-- Q1.Return the name of the person with ID `person0'. let $auction := doc("auction.xml") return for $b in $auction/site/people/person[@id = "person0"] return $b/name/text() -- Q2. Return the initial increases of all open auctions. let $auction := doc("auction.xml") return for $b in $auction/site/open_auctions/open_auction return {$b/bidder[1]/increase/text()} -- Q3. Return the IDs of all open auctions whose current -- increase is at least twice as high as the initial increase. let $auction := doc("auction.xml") return for $b in $auction/site/open_auctions/open_auction where zero-or-one($b/bidder[1]/increase/text()) * 2 <= $b/bidder[last()]/increase/text() return -- Q4. List the reserves of those open auctions where a -- certain person issued a bid before another person. let $auction := doc("auction.xml") return for $b in $auction/site/open_auctions/open_auction where some $pr1 in $b/bidder/personref[@person = "person20"], $pr2 in $b/bidder/personref[@person = "person51"] satisfies $pr1 << $pr2 return {$b/reserve/text()} -- Q5. How many sold items cost more than 40? let $auction := doc("auction.xml") return count( for $i in $auction/site/closed_auctions/closed_auction where $i/price/text() >= 40 return $i/price ) -- Q6. How many items are listed on all continents? let $auction := doc("auction.xml") return for $b in $auction//site/regions return count($b//item) -- Q7. How many pieces of prose are in our database?} let $auction := doc("auction.xml") return for $p in $auction/site return count($p//description) + count($p//annotation) + count($p//emailaddress) -- Q8. List the names of persons and the number of items they bought. -- (joins person, closed\_auction)} let $auction := doc("auction.xml") return for $p in $auction/site/people/person let $a := for $t in $auction/site/closed_auctions/closed_auction where $t/buyer/@person = $p/@id return $t return {count($a)} -- Q9. List the names of persons and the names of the items they bought -- in Europe. (joins person, closed\_auction, item)} let $auction := doc("auction.xml") return let $ca := $auction/site/closed_auctions/closed_auction return let $ei := $auction/site/regions/europe/item for $p in $auction/site/people/person let $a := for $t in $ca where $p/@id = $t/buyer/@person return let $n := for $t2 in $ei where $t/itemref/@item = $t2/@id return $t2 return {$n/name/text()} return {$a} -- Q10. List all persons according to their interest; -- use French markup in the result. let $auction := doc("auction.xml") return for $i in distinct-values($auction/site/people/person/profile/interest/@category) let $p := for $t in $auction/site/people/person where $t/profile/interest/@category = $i return {$t/profile/gender/text()} {$t/profile/age/text()} {$t/profile/education/text()} {fn:data($t/profile/@income)} {$t/name/text()} {$t/address/street/text()} {$t/address/city/text()} {$t/address/country/text()} {$t/emailaddress/text()} {$t/homepage/text()} {$t/creditcard/text()} return {{$i}, $p} -- Q11. For each person, list the number of items currently on sale whose -- price does not exceed 0.02% of the person's income. let $auction := doc("auction.xml") return for $p in $auction/site/people/person let $l := for $i in $auction/site/open_auctions/open_auction/initial where $p/profile/@income > 5000 * exactly-one($i/text()) return $i return {count($l)} -- Q12. For each richer-than-average person, list the number of items -- currently on sale whose price does not exceed 0.02% of the -- person's income. let $auction := doc("auction.xml") return for $p in $auction/site/people/person let $l := for $i in $auction/site/open_auctions/open_auction/initial where $p/profile/@income > 5000 * exactly-one($i/text()) return $i where $p/profile/@income > 50000 return {count($l)} -- Q13. List the names of items registered in Australia along with -- their descriptions. let $auction := doc("auction.xml") return for $i in $auction/site/regions/australia/item return {$i/description} -- Q14. Return the names of all items whose description contains the -- word `gold'. let $auction := doc("auction.xml") return for $i in $auction/site//item where contains(string(exactly-one($i/description)), "gold") return $i/name/text() -- Q15. Print the keywords in emphasis in annotations of closed auctions. let $auction := doc("auction.xml") return for $a in $auction/site/closed_auctions/closed_auction/annotation/description/parlist/ listitem/ parlist/ listitem/ text/ emph/ keyword/ text() return {$a} -- Q16. Return the IDs of those auctions -- that have one or more keywords in emphasis. (cf. Q15) let $auction := doc("auction.xml") return for $a in $auction/site/closed_auctions/closed_auction where not( empty( $a/annotation/description/parlist/listitem/parlist/listitem/text/emph/ keyword/ text() ) ) return -- Q17. Which persons don't have a homepage? let $auction := doc("auction.xml") return for $p in $auction/site/people/person where empty($p/homepage/text()) return -- Q18.Convert the currency of the reserve of all open auctions to -- another currency. declare namespace local = "http://www.foobar.org"; declare function local:convert($v as xs:decimal?) as xs:decimal? { 2.20371 * $v (: convert Dfl to Euro :) }; let $auction := doc("auction.xml") return for $i in $auction/site/open_auctions/open_auction return local:convert(zero-or-one($i/reserve)) -- Q19. Give an alphabetically ordered list of all -- items along with their location. let $auction := doc("auction.xml") return for $b in $auction/site/regions//item let $k := $b/name/text() order by zero-or-one($b/location) ascending empty greatest return {$b/location/text()} -- Q20. Group customers by their -- income and output the cardinality of each group. let $auction := doc("auction.xml") return {count($auction/site/people/person/profile[@income >= 100000])} { count( $auction/site/people/person/ profile[@income < 100000 and @income >= 30000] ) } {count($auction/site/people/person/profile[@income < 30000])} { count( for $p in $auction/site/people/person where empty($p/profile/@income) return $p ) }