我有一个查询,它总结了SQL Server中给定月份在给定时间段内的事务。我想在一个表中列出月份和事务,但是DATENAME()
函数只返回列表中的一个月,即1月。查询如下所示。
SELECT
DATENAME(MONTH, DATEPART(MONTH FROM TransactionDate)) AS Month_Name,
SUM(ABS(Income)) AS Income
FROM
Transactions
GROUP BY
DATEPART(MONTH FROM TransactionDate)
Please help…
试试这个,
SELECT
datename(mm,TransactionDate) AS Month_Name,
SUM(ABS(Income)) AS Income
FROM Transactions
GROUP BY
datename(mm, TransactionDate)
试试这个:
select datename(mm, TransactionDate) month_name, sum(income) income
from transactions
group by month_name
删除一些不必要的优化性能。