|
SELECT dbo.Orders.Id, dbo.Orders.OrderDate, dbo.Orders.Journal, dbo.Orders.Billing,
Billing.Name AS BillingName, Billing.Email AS BillingEmail,
Billing.Address + ',' + Billing.Region AS BillingAddress, Billing.Zip AS BillingZip,
Billing.Phone AS BillingPhone, dbo.Orders.Shipping,
Shipping.Name AS ShippingName, Shipping.Email AS ShippingEmail,
Shipping.Address + ',' + Shipping.Region AS ShippingAddress,
Shipping.Zip AS ShippingZip, Shipping.Phone AS ShippingPhone,
dbo.Orders.Payment, dbo.Payment.Holder, dbo.Payment.Credit, dbo.Payment.Expire,
COUNT(dbo.Details.ProductId) AS Quantity, SUM(dbo.Product.Price) AS Total,
dbo.Orders.Status
FROM dbo.Orders INNER JOIN
dbo.Details ON dbo.Orders.Id = dbo.Details.OrderId INNER JOIN
dbo.Contact AS Shipping ON dbo.Orders.Shipping = Shipping.Id INNER JOIN
dbo.Contact AS Billing ON dbo.Orders.Billing = Billing.Id INNER JOIN
dbo.Product ON dbo.Details.ProductId = dbo.Product.Id INNER JOIN
dbo.Payment ON dbo.Orders.Payment = dbo.Payment.Id
GROUP BY dbo.Orders.Id, dbo.Orders.OrderDate, dbo.Orders.Journal, dbo.Orders.Billing,
Billing.Name, Billing.Email, Billing.Address, Billing.Region, Billing.Zip, Billing.Phone,
dbo.Orders.Shipping, Shipping.Name, Shipping.Email, Shipping.Address,
Shipping.Region, Shipping.Zip, Shipping.Phone, dbo.Orders.Payment,
dbo.Payment.Holder, dbo.Payment.Credit, dbo.Payment.Expire, dbo.Orders.Status
一个产品订单。
订单表Orders表,里面有Billing和Shiping、Payment字段,记录付款联系信息、越洋邮寄地址信息。另外一个Details表,记录详细订单信息,包括对应的OrderId,以及产品编号ProductId,这样就可以用COUNT(dbo.Details.ProductId) AS Quantity, SUM(dbo.Product.Price) AS Total, 分别统计出订单包含的产品总数和总金额。问题是为什么统计不出来总金额?
|
|