Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to group by each day in PL/SQL?

Tags:

sql

oracle

plsql

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.

What Im currently doing:

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

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

Any help? :D

like image 592
Jason94 Avatar asked Apr 12 '12 12:04

Jason94


1 Answers

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

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

like image 115
Erkan Haspulat Avatar answered Sep 30 '22 03:09

Erkan Haspulat