2017-10-08 21 views
-1

如何使用XQuery獲得最高價格?我正在嘗試學習XML和XQuery的基礎知識,並提前致謝!如何使用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> 

回答

2

最高價格簡直就是max(//price)。如果您想要價格最高的圖書,最簡單的方法是//book[price=max(//price)],但這並不一定是最高效的(取決於您的優化程序)。