|
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
One product order.
Orders table Orders table, which contains Billing, Shiping, Payment fields, records payment contact information, overseas shipping address information. Another Details table records detailed order information, including the corresponding OrderId and product ID ProductId, so that you can use COUNT (dbo.Details.ProductId) AS Quantity, SUM (dbo.Product.Price) AS Total, to separately count the orders The total number and total amount of products included. The question is why the total amount cannot be calculated? |
|