答案 0 :(得分:0)
如果您使用的是tSQL,应该这样做,但不同年份的相同月份呢?
;WITH CTE AS (
SELECT DATENAME(month,SignUpTime) AS [MonthName],
COUNT(UserID) AS [CountUsers]
FROM Tbl_Users
GROUP BY DATENAME(month,SignUpTime))
UPDATE A
SET A.[CountUsers]=B.[CountUsers]
FROM Tbl_CountUsersPerMonth AS A LEFT OUTER JOIN
CTE AS B ON A.[MonthName]=B.[MonthName]
答案 1 :(得分:0)
我建议您使用以下表格代替表格:
CREATE VIEW vw_CountUsersPerMonth
AS
SELECT YEAR(SignUpTime) as [Year],
DATENAME(month,SignUpTime) AS [MonthName],
COUNT(UserID) AS [CountUsers]
FROM Tbl_Users
GROUP BY YEAR(SignUpTime), DATENAME(month,SignUpTime))