我试图运行Oracle SELECT查询,其中一个GROUP BY字段是表达式:
SELECT CUSTOMER, TO_CHAR(EVENT_DATE, 'HH:MI:SS AM') AS "EVENT_TIME", COUNT(*) as "EVENT_COUNT"
FROM events
GROUP BY CUSTOMER,EVENT_TIME;
但我收到此错误消息:
ORA-00904:" EVENT_TIME":无效标识符
如果我使用文字表达式而不是标识符:
SELECT CUSTOMER, TO_CHAR(EVENT_DATE, 'HH:MI:SS AM') AS "EVENT_TIME", COUNT(*) as "EVENT_COUNT"
FROM events
GROUP BY CUSTOMER,TO_CHAR(EVENT_DATE, 'HH:MI:SS AM');
我得到了一个不同的错误:
ORA-00979:不是GROUP BY表达式
我可以在GROUP BY子句中使用表达式吗?如果是这样,怎么样?