Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SQL查看/查询以返回当月的总和_Sql_Sql Server_Date_Sum - Fatal编程技术网

SQL查看/查询以返回当月的总和

SQL查看/查询以返回当月的总和,sql,sql-server,date,sum,Sql,Sql Server,Date,Sum,很抱歉问这么一个新手问题,但我是个新手 SELECT SUM([Sales Total]) AS Sales, Salesperson, Date FROM dbo.[Sales by Salesperson] GROUP BY Date, Salesperson 尝试仅返回当月销售人员的销售额总和 Example: Jaime Smith | 1,000,000 John Doe | 1,200,000 我有销售人员的数据,但不知道如何只显示当月。试试

很抱歉问这么一个新手问题,但我是个新手

SELECT     SUM([Sales Total]) AS Sales, Salesperson, Date
FROM         dbo.[Sales by Salesperson]
GROUP BY Date, Salesperson
尝试仅返回当月销售人员的销售额总和

Example:
Jaime Smith   | 1,000,000
John Doe      | 1,200,000
我有销售人员的数据,但不知道如何只显示当月。

试试这个

Example:
Jaime Smith   | 1,000,000
John Doe      | 1,200,000
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)
试试这个

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

您的数据库是SQL Server吗?只是想确认一下?按日期分组也会将结果除以日期部分,因此不起作用。哦,是的,你是对的。应按年(日期)、月(日期)分组