Sha256: fe01e3bf14e4083da261b0c59d837ccbaf23328390d97cb9c8521e95183d4d8f

Contents?: true

Size: 776 Bytes

Versions: 2

Compression:

Stored size: 776 Bytes

Contents

declare function local:bid_summary()
  as element()*
{
    for $i in distinct-values(doc("bids.xml")//itemno)
    let $b := doc("bids.xml")//bid_tuple[itemno = $i]
    return
        <bid_count>
            <itemno>{ $i }</itemno>
            <nbids>{ count($b) }</nbids>
        </bid_count>
};

<result>
 {
    let $bid_counts := local:bid_summary(),
        $maxbids := max($bid_counts/nbids),
        $maxitemnos := $bid_counts[nbids = $maxbids]
    for $item in doc("items.xml")//item_tuple,
        $bc in $bid_counts
    where $bc/nbids =  $maxbids and $item/itemno = $bc/itemno
    return
        <popular_item>
            { $item/itemno }
            { $item/description }
            <bid_count>{ $bc/nbids/text() }</bid_count>
        </popular_item>
 }
</result>

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
magic_xml-0.1.1 xquery_use_cases/rdb/q12.xquery
magic_xml-0.1.0 xquery_use_cases/rdb/q12.xquery