简体   繁体   English

SQL View / Query返回当前月份的总和

[英]SQL View/Query to return sum by current month

Sorry for such a newbie question but I am that a newbie. 很抱歉遇到这样一个新手问题,但我就是那个新手。

SELECT     SUM([Sales Total]) AS Sales, Salesperson, Date
FROM         dbo.[Sales by Salesperson]
GROUP BY Date, Salesperson

Trying to return only the SUM of Sales by Salesperson by current month. 尝试仅按当月返回销售员的销售总和。

Example:
Jaime Smith   | 1,000,000
John Doe      | 1,200,000

I have the data pulling for the Salesperson but don't know how to show only the current month. 我有推销员的数据,但不知道如何仅显示当前月份。

Try this... 尝试这个...

SELECT SUM([Sales Total]) AS Sales,
    Salesperson,
    YEAR(Date) [Year],
    MONTH(Date) [Month]
FROM dbo.[Sales by Salesperson]
WHERE YEAR(Date) = YEAR(GETDATE()) AND MONTH(Date) = MONTH(GETDATE()) /*To filter by month*/
GROUP BY Salesperson, YEAR(Date), MONTH(Date)

try this 尝试这个

SELECT SUM([Sales Total]) AS Sales, Salesperson, Date
FROM dbo.[Sales by Salesperson]
where year(date) = year(getdate())
and month(date) = month(getdate())
GROUP BY Date, Salesperson

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM