zoukankan      html  css  js  c++  java
  • Xquery的初步学习(一次Lab作业的总结)

    Task 1: Open countries.xml, compose the following XQueries:

    1. Return the area of Mongolia.

    2. Return the names of all cities that have the same name as the country in which they are located.

    3. Return the average population of Russian-speaking countries.

    4. Returnthenamesofallcountrieswhereover50%ofthepopulationspeaksGerman. (Hint: Dependingonyoursolution, you may want to use ".", which refers to the "current element" within an XPath expression.)

    5. Returnthenameofthecountrywiththehighestpopulation. (Hint: Youmayneedtoexplicitlycastpopulationnumbers as integers with xs:int() to get the correct answer.)

    第一问:

    for $x in doc("countries.xml")/countries/country
    where $x/@name="Mongolia"
    return <area>{data($x/@area)}</area>

    第二问:

    for $x in doc("countries.xml")/countries/country
    for $y in $x/city
    where $y/name= $x/@name
    return $y/name 

    第三问:

    avg(doc("countries.xml")/countries/country[language="Russian"]/@population)

    第四问:

    for $i in (doc("countries.xml")/countries/country/language[@percentage>50 and .="German"]/../@name)
            return <name>{data($i)}</name>

    第五问:

    for $x in doc("countries.xml")/countries/country
    where $x/@population = max(doc("countries.xml")/countries/country/@population)
    return <name>{data($x/@name)}</name>
  • 相关阅读:
    20201216-1 文件读与写详解3
    20201214-4 文件读与写详解2
    20201214-3 文件读与写详解1
    20201214 集合及其运算
    3月17日:毕业设计计划
    3月16日:毕业设计计划
    3月15日:毕业设计计划
    3月14日:毕业设计计划
    3月13日:毕业设计计划
    3月12日:毕业设计计划
  • 原文地址:https://www.cnblogs.com/northernmashiro/p/9080390.html
Copyright © 2011-2022 走看看