次のSQLをに変換しようとしています
SELECT SUM((((1-Discount)*Quantity)*[Unit Price])) AS AMOUNT
FROM Orders
LEFT JOIN [Order Details]
ON Orders.[Order ID] = [Order Details].[Order ID]
WHERE ((([Order Date]) BETWEEN #1/1/2006# AND #2/1/2006#));
注文と注文の詳細には1対多の関係があります(1は注文との関係です)
私が現在持っているコードは、各注文の詳細の全額を表示しますが、注文の詳細の各合計値を組み合わせて完全な値を取得することはできません。
for $orderdetails in doc("Order Details.xml")/dataroot/Order_x0020_Details
let $order := doc("Orders.xml")/dataroot/Orders[OrderID = $orderdetails/OrderID]
where xs:dateTime($order/OrderDate/text()) gt xs:dateTime("1996-04-06T00:00:00") and xs:dateTime($order/OrderDate/text()) lt xs:dateTime("1997-04-05T00:00:00")
return
<Invoice_Amounts>
{
$order/OrderID
}
<Amount>
{
sum(((1 - xs:double($orderdetails/Discount)) * xs:double($orderdetails/UnitPrice)) * xs:double($orderdetails/Quantity))
}
</Amount>
</Invoice_Amounts>
のサンプルOrders.xml
<OrderID>10248</OrderID>
<CustomerID>WILMK</CustomerID>
<EmployeeID>5</EmployeeID>
<OrderDate>1996-07-04T00:00:00</OrderDate>
<RequiredDate>1996-08-01T00:00:00</RequiredDate>
<ShippedDate>1996-07-16T00:00:00</ShippedDate>
<ShipVia>3</ShipVia>
<Freight>32.38</Freight>
<ShipName>Vins et alcools Chevalier</ShipName>
<ShipAddress>59 rue de l'Abbaye</ShipAddress>
<ShipCity>Reims</ShipCity>
<ShipPostalCode>51100</ShipPostalCode>
<ShipCountry>France</ShipCountry>
</Orders>
<Orders>
<OrderID>10249</OrderID>
<CustomerID>TRADH</CustomerID>
<EmployeeID>6</EmployeeID>
<OrderDate>1996-07-05T00:00:00</OrderDate>
<RequiredDate>1996-08-16T00:00:00</RequiredDate>
<ShippedDate>1996-07-10T00:00:00</ShippedDate>
<ShipVia>1</ShipVia>
<Freight>11.61</Freight>
<ShipName>Toms Spezialitäten</ShipName>
<ShipAddress>Luisenstr. 48</ShipAddress>
<ShipCity>Münster</ShipCity>
<ShipPostalCode>44087</ShipPostalCode>
<ShipCountry>Germany</ShipCountry>
</Orders>
`OrderDetails.xmlのサンプル
<OrderID>10248</OrderID>
<ProductID>11</ProductID>
<UnitPrice>14</UnitPrice>
<Quantity>12</Quantity>
<Discount>0</Discount>
</Order_x0020_Details>
<Order_x0020_Details>
<OrderID>10248</OrderID>
<ProductID>42</ProductID>
<UnitPrice>9.8</UnitPrice>
<Quantity>10</Quantity>
<Discount>0</Discount>
</Order_x0020_Details>
<Order_x0020_Details>
<OrderID>10248</OrderID>
<ProductID>72</ProductID>
<UnitPrice>34.8</UnitPrice>
<Quantity>5</Quantity>
<Discount>0</Discount>
</Order_x0020_Details>
<Order_x0020_Details>
<OrderID>10249</OrderID>
<ProductID>14</ProductID>
<UnitPrice>18.6</UnitPrice>
<Quantity>9</Quantity>
<Discount>0</Discount>
</Order_x0020_Details>