• 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>
  • 相关阅读:
    window10 禁止更新
    安装node.msi 格式的文件失败
    url参数的转码和解码
    Linux12-内存管理
    C++四种cast
    Linux内核5-系统调用
    Linux内核3-进程管理
    UNIX12-线程(下)线程控制
    UNIX11-线程(上)
    Linux内核8-中断下半部和推后执行的工作(下半部)
  • 原文地址:https://www.cnblogs.com/northernmashiro/p/9080390.html
Copyright © 2020-2023  润新知