每月分组
SELECT
Sum(Earning) AS Amount,
MONTH(DateCreated) AS Month
FROM
TheTable
WHERE
DateCreated
BETWEEN
@DateFrom AND @DateTo
GROUP BY **???**
我想要显示每月收入,如果它再次出现在下一年,则不应将该月份分组
May ,Jun,Jul,Aug,Sep,Oct,Nov,Dec,Jan,Feb,Mar,Apr, May ,June等
意思是如果年份不同,它应该继续没有分组的列表,例如2015年5月和2016年5月。
谢谢
在select
和group by
包含年份:
SELECT YEAR(DateCreated) as Year, MONTH(DateCreated) AS Month,
Sum(Earning) AS Amount
FROM TheTable
WHERE DateCreated BETWEEN @DateFrom AND @DateTo
GROUP BY YEAR(DateCreated), MONTH(DateCreated)
ORDER BY YEAR(DateCreated), MONTH(DateCreated);
您可以按月使用功能分组()
SELECT
Sum(Earning) AS Amount,
MONTH(DateCreated) AS Month
FROM
TheTable
WHERE
DateCreated
BETWEEN
@DateFrom AND @DateTo
GROUP BY MONTH(DateCreated)
链接地址: http://www.djcxy.com/p/65617.html
上一篇: Grouping per month