Grouping per month
SELECT
Sum(Earning) AS Amount,
MONTH(DateCreated) AS Month
FROM
TheTable
WHERE
DateCreated
BETWEEN
@DateFrom AND @DateTo
GROUP BY **???**
I want to display Earning per month and it should not group the month if it appears next year again eg
May , Jun, Jul, Aug, Sep, Oct, Nov, Dec, Jan, Feb, Mar, Apr, May , June etc.
Meaning if the year differs it should continue the list without grouping eg May 2015 and May 2016 altogether.
Thank you
在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/65618.html
上一篇: 每月就开始日期和结束日期分配金额
下一篇: 每月分组