XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Conferences Close Tree View
+ Stylus Studio Feature Requests (1192)
+ Stylus Studio Technical Forum (14621)
+ Website Feedback (249)
+ XSLT Help and Discussion (7625)
- XQuery Help and Discussion (2017)
-> + Issue with Processing Instruct... (2)
-> + problem converting json to XML... (2)
-> + Problem base64 decoding string... (3)
-> + Problems posting multipart for... (5)
-> + trouble with download of price... (2)
-> + Problem with http-post not bei... (3)
-> + path problem, xps_file:writeAl... (9)
-> + Xquery update support? (2)
-> + problem with Stylus studio try... (5)
-> + adding dtd reference to xml ou... (4)
-> + xquery escaping ambarsand when... (3)
-> + Whitespace problem when return... (5)
-> + Problem with namespace prefix ... (5)
-> - Sending via SFTP returns unexp... (1)
-> + Query and Sftp clent (4)
-> + xquery and try - catch (3)
-> + Query + ddtek:http-post optio... (5)
-> + Example files referenced in do... (3)
-> + Automatic Error Detection and ... (3)
-> + Working with result of ddtek:h... (2)
-- [1-20] [21-40] [41-60] Next
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
Topic  
Postnext
sap pageSubject: Xquery find avg and count
Author: sap page
Date: 29 May 2006 08:23 AM
Originally Posted: 29 May 2006 08:05 AM
I currently have a bit of a problem with my uni assignment and was wondering if anyone could help. This was about the only xquery site i could find a forum on.

Write a query to find all products whose sale price is more than twice the average price of some other product within the same type. Display the total number of products with such high prices for each type. Also display the name and price of these products. For each type, the product must be listed in increasing order by price.

output

<Expensive-products>
<Expensive-products-on-Microsoft>
<Total-number> …. </Total-number>
<product>
<name> …. </name>
<price> …. </price>
<product>
<product> ….</product>
</ Expensive-products-on-Microsoft>
………
</Expensive-products>

products

<products>
<product type ="microsoft_technologies">
<name> VB </name>
<price> 100 </price>
<number> 50 </number>
</product>
………

Postnext
sap pageSubject: Xquery
Author: sap page
Date: 29 May 2006 08:10 AM
for $products in distinct-values(doc("products.xml")/products/product/@type)
return

for $type in doc("products.xml")/products/product[@type=$products]
let $avg_price := doc("products.xml")/products/product[@type=$type/@type]/price/text()
let $avg := doc("products.xml")/products/product[@type=$products]
for $t in $avg/price/text()
where avg($t)*2 < $type/price/text()
return count($t)

This is what I have so far just so you dont think i am using the forums to get free answers!

Posttop
Ivan PedruzziSubject: Xquery
Author: Ivan Pedruzzi
Date: 29 May 2006 10:38 PM

Is something like the following works for you?

for $type in distinct-values(doc("products.xml")/products/product/@type)
let $products_by_type := doc("products.xml")/products/product[@type=$type]
let $products_count := count($products_by_type)
let $price_average := avg($products_by_type/price/text())
let $expensive_products := $products_by_type[price/text() > $price_average * 2]
return
(
count($expensive_products),
for $product in $expensive_products
return $product/name/text()
)

Hope this helps
Ivan Pedruzzi
Stylus Studio Team

   
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.