我无法运行以下查询。
我需要在每周的每一天找到每个模型使用的 [ID] 数量。我运行类似的查询来总结其他指标没有问题。
但在这种情况下,我收到一条消息“将 varchar 值 '07:2767:90:56' 转换为数据类型 int 时转换失败”。
我可以在没有(case if)函数的情况下对 [ID] 执行计数查询,没有任何问题。
SELECT model,
count(CASE WHEN datepart(weekday, [date]) =2 THEN (ID)else 0 END) AS [Monday]
count(CASE WHEN datepart(weekday, [date]) =3 THEN (ID)else 0 END) AS [Tuesday]
count(CASE WHEN datepart(weekday, [date]) =4 THEN (ID)else 0 END) AS [Wednesday]
count(CASE WHEN datepart(weekday, [date]) =5 THEN (ID)else 0 END) AS [Thursday]
count(CASE WHEN datepart(weekday, [date]) =6 THEN (ID)else 0 END) AS [Friday]
from clientdata
where [date] between cast ((GETDATE() -7) AS date) and cast (GETDATE()-1 AS date)
group by d.model;