我有这样的 SQL:
SELECT
Mid(Note,
InStr(Note, "device.")-
(
InStr(Note, "device.")-
InStr(Note, "pressure and")
)
+13,
(InStr(Note, "device.") - InStr(Note, "pressure and")) - 14
)
AS [Device],
Count([Device]),
Date_Field & " " & Time_Field AS [DateTime],
EnteredBy
FROM MyLog
WHERE Note LIKE "*removed and*"
GROUP BY [Device]
ORDER BY Date_Field DESC
;
我想要GROUP BY
那个自定义字段[Device]
并计算每个设备有多少。但是上面的代码为“... AS [Device]”部分给出了错误“...不包括指定的表达式...作为聚合函数的一部分”。
我怎样才能做到这一点?
现在数据看起来像:
Record1 12/05/12 03:02:12 User2
Record1 12/02/12 01:02:12 User1
Record1 12/01/12 02:02:12 User2
Record2 12/06/12 03:02:12 User2
Record2 12/07/12 03:02:12 User3
但我希望它看起来像:
Record1 3
Record2 2
这是有效的旧 SQL(不聚合):
SELECT Mid(Note,
InStr(Note, "device.")-
(
InStr(Note, "device.")-
InStr(Note, "pressure and")
)
+13,
(InStr(Note, "device.") - InStr(Note, "pressure and")) - 14
) AS Device, Date_Field & " " & Time_Field AS [DateTime], EnteredBy
FROM MyLog
WHERE Note LIKE "*removed and*"
ORDER BY Date_Field DESC;