我接近解决这个问题,但需要轻推才能完成。我的数据集有 1 月、2 月和 3 月的记录。
enter code here
Select
cartypes.TypeName,
Count(cartypes.TypeName) As Count,
COUNT(MONTH(maindata.CreatedDate) = 1) As Jan,
COUNT(MONTH(maindata.CreatedDate) = 2) As Feb
From maindata
Inner Join cartypes
On maindata.TypeID = cartypes.CarType_ID
Group By cartypes.TypeName
我的输出如下所示:
TypeName Count Jan Feb
Accreditation Audit 23 1 0
Certificate Decision 5 1 0
Certification Decision 2 1 0
Complaint About Client 1 1 0
Customer Complaint 3 1 0
Internal Audit 5 1 0
Internal Finding 7 1 0
Preventative Action 1 1 0
Witness Audit 1 0 1
我尝试了几种不同的方法来尝试让每个记录的各种 TypeName 的计数在每个月都正确计数,但是我碰壁了。例如,Jan 应该显示认证审核的计数为 23,Feb 应该有 2 个认证决定和 1 个见证审核。
我希望我已经足够清楚了。