sql-server – 每月销售总额

前端之家收集整理的这篇文章主要介绍了sql-server – 每月销售总额前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我觉得这很常见,是吗?

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

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)
原文链接:https://www.f2er.com/mssql/75932.html

猜你在找的MsSQL相关文章