-1

我想要一个选择结果,我可以在其中获得每天的结果。我计算错误,并有以下非工作声明:

SELECT message, time, personid, count(*)
FROM errorlog
WHERE time BETWEEN TO_DATE(todays date - 10 days) AND TO_DATE(todays date) AND SUBSTR(message,0,3) = 'ERR'
GROUP BY DAY(time), personid, message
ORDER BY 4

当我运行它时,它显示“DAY”:无效标识符。

4

3 回答 3

1

它应该是 GROUP BY 之后的列名。

尝试:

SELECT message, DAY(time) dayTime, personid, count(*)
FROM errorlog
WHERE time BETWEEN TO_DATE(todays date - 10 days) AND TO_DATE(todays date) AND SUBSTR(message,0,3) = 'ERR'
GROUP BY dayTime, personid, message
ORDER BY 4
于 2012-04-11T10:00:19.887 回答
0

您中的任何项目GROUP BY也必须在您的SELECT.

如果您按天分组,并且显示time(我怀疑它是日期时间数据类型),并且您在哪一天有 2 条记录,那么您的结果集将如何显示这两个不同的时间?本来就不行。

以下查询使用和 的CONVERT(VARCHAR(10), time, 103)含义,即在您的结果集中显示一个格式,并且您的记录将按此分组。SELECTGROUP BYdd/MM/yyyy

SELECT message, CONVERT(VARCHAR(10), time, 103), personid, count(*)
FROM errorlog
WHERE time BETWEEN TO_DATE(todays date - 10 days) AND TO_DATE(todays date) AND SUBSTR(message,0,3) = 'ERR'
GROUP BY CONVERT(VARCHAR(10), time, 103), personid, message
ORDER BY 4
于 2012-04-11T09:55:27.227 回答
-1

SQL 服务器?

纠正这个:

SELECT message, DAY(time) AS [DAY], personid, count(*)
于 2012-04-11T09:57:30.073 回答