如何使用Xquery获得最高价格

时间:2017-10-08 22:52:30

标签: xml xquery

如何使用XQuery获得最高价格?我正在尝试学习XML和XQuery的基础知识,并提前感谢!

    <catalog>
    <book id="bk101">
      <author>Gambardella, Matthew</author>
      <title>XML Developer's Guide</title>
      <genre>Computer</genre>
      <price>44.95</price>
      <publish_date>2000-10-01</publish_date>
      <description>An in-depth look at creating applications 
      with XML.</description>
   </book>
   <book id="bk102">
      <author>Ralls, Kim</author>
      <title>Midnight Rain</title>
      <genre>Fantasy</genre>
      <price>5.95</price>
      <publish_date>2000-12-16</publish_date>
      <description>A former architect battles corporate zombies, 
      an evil sorceress, and her own childhood to become queen 
      of the world.</description>
   </book>
</catalogue>

1 个答案:

答案 0 :(得分:2)

最高价格只是max(//price)。如果您想要价格最高的图书,最简单的方法是//book[price=max(//price)],但这并不一定是最有效的(取决于您的优化工具)。