每月总销售额

2021-09-10 00:00:00 tsql sql-server

如果您有一个带有 SALES {Customer_ID, Price, SmallDateTime date} 的表格.您如何报告每月的所有销售额?

If you have a table with SALES {Customer_ID, Price, SmallDateTime date}. How do you report all sales per month?

SELECT Sum(Price) As Total Sales FROM SALES Group By What Having What 

推荐答案

  SELECT YEAR(date) as SalesYear,
         MONTH(date) as SalesMonth,
         SUM(Price) AS TotalSales
    FROM Sales
GROUP BY YEAR(date), MONTH(date)
ORDER BY YEAR(date), MONTH(date)

相关文章