如何在 PL/SQL 中按每天分组?

2021-12-24 00:00:00 sql oracle plsql

我正在尝试使用 PL/SQL 获取每天的统计数据.

Im trying to get statistics for each day with PL/SQL.

每天都有几个条目,错误的 :-) 我想按天对它们进行分组.

Each day have several entries, bukkets of errors :-) I want to group them by day.

我目前在做什么:

SELECT TO_CHAR(dateTime, 'DD') DAY, TO_CHAR(dateTime, 'MM') MONTH, errormessage
FROM log
WHERE (...)
GROUP BY MONTH, DAY, errormessage

这会导致 ORA-00904:DAY":无效标识符(在 group by 上停止).

This results in ORA-00904: "DAY": invalid identifier (stops on the group by).

有什么帮助吗?:D

推荐答案

SELECT TO_CHAR(dateTime, 'DD') DAY, TO_CHAR(dateTime, 'MM') MONTH, errormessage
FROM log
WHERE (...)
GROUP BY TO_CHAR(dateTime, 'DD'), TO_CHAR(dateTime, 'MM'), errormessage

列别名不适用于GROUP BY,你需要完整的表达式.

Column aliases are no good for GROUP BY, you need the full expression.

相关文章