0

我无法获得 XQuery 来计算两年内的销售额,它基于 SQL 查询。

SELECT [ShipCountry] & " " & [ShipCity] AS CountryAndCity, COUNT(OrderID) AS BiYearlySales
FROM Orders
WHERE (((OrderDate) BETWEEN #1/1/1996# And #1/1/1998#))
GROUP BY [ShipCountry] & " " & [ShipCity];

这是迄今为止我得到的 xquery,但它只计算每个实例一次。想不通为什么。我正在使用 Altova xmlspy - xquery 1.0。

<Result>
{
for $a in doc("Orders.xml")/dataroot/Orders
let $b := concat($a/ShipCountry, " ", $a/ShipCity)
where $a/OrderDate >= '1996-01-01T00:00:00' and $a/OrderDate <= '1998-01-01T00:00:00'
return
<BiYearlySales>
    <CountryNameAndCity>{$b}</CountryNameAndCity>
    <OrderCount>{count($a)}</OrderCount>
</BiYearlySales>
}
</Result>

我意识到我还没有完成这个小组,但尝试让这个工作更重要。

4

1 回答 1

0

不确定这是否完全正确......(没有尝试过)但是是这样的:

for $country in doc("Orders.xml")/dataroot/Orders[OrderDate ge '1996-01-01T00:00:00' and OrderDate le '1998-01-01T00:00:00']/ShipCountry, $city in doc(doc("Orders.xml")/dataroot/Orders[OrderDate ge '1996-01-01T00:00:00' and OrderDate le '1998-01-01T00:00:00']/ShipCity")
return 
<sales>
   <geo>{$country, " ", $city)}</geo>
   <count>{count(doc("Orders.xml")/dataroot/Orders
           [OrderDate ge '1996-01-01T00:00:00' and OrderDate le '1998-01-01T00:00:00' 
            and ShipCountry eq $country and ShipCity eq $city])}
   </count>
</sales>
于 2012-03-12T22:44:10.700 回答