查询以计算客户发送的金额以及他发出的总订单

时间:2017-01-12 12:23:19

标签: mysql

我是Northwind示例数据库。它有8个表(CustomersCategoriesEmployeesOrderDetailsOrdersProductsShipper和{{1我应用查询来计算每个客户的总订单数量和他迄今为止所花的钱。查询在这里:

Suppliers

但它没有正确计算totalOrders。我从4个表select c.CustomerID, SUM(p.Price*od.Quantity) as Totalspent, COUNT(o.OrderID) AS TotalOrder from Orders o LEFT join Customers c ON c.CustomerID = o.CustomerID join [OrderDetails] od on od.OrderID = o.OrderID join Products p on od.ProductID = p.ProductID group by c.CustomerID order by c.customerid OrdersCustomersOrderDetails中提取数据。检查表的以下链接。 http://www.w3schools.com/sql/trysql.asp?filename=trysql_select_all

0 个答案:

没有答案