( FOR $i IN DISTINCT document("bids.xml")//itemno LET $b := document("bids.xml")//bid_tuple[itemno = $i] WHERE count($b) >= 3 RETURN $i , avg($b/bid) SORTBY (avgbid) DESCENDING )