我正在使用NorthWind SQL数据库。对于不熟悉的人,它具有一些下表:

 Orders,
 OrderDetails,
 Products,
 categories
 (Orders.OrderID = OrderDetails.OrderID)
 (Products.ProductID = OrderDetails.ProductID)
 (Categories.categoryID = Products.categoryID)

 Orders has a column named "OrderDate" (formatted as dd/mm/yy)
 OrderDetails has a column named "Price"


我需要显示每年的总“收入”。即,所有“价格”之和。知道怎么做吗?

最佳答案

请尝试这样的操作,因为我们没有完整的表结构。这种GROUP BY用于MySQL

   SELECT SUM (OD.Price) AS Revenue FROM OrderDetails OD
    INNER JOIN Orders O ON Orders.OrderID = OrderDetails.OrderID
    GROUP BY YEAR(O.OrderDate);

关于mysql - 显示每年的收入,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29396763/

10-11 21:33