【发布时间】:2012-07-04 17:34:35
【问题描述】:
我有一个 SQL 查询,我使用 Oracle CASE 来比较日期列是小于还是大于当前日期。但是我如何在GROUP BY-statement 中使用CASE-statement?我想统计每种情况下的记录。
例如
select
(case
when exp_date > sysdate then 1
when exp_date <= sysdate then 2
else 3
end) expired, count(*)
from mytable
group by expired
但尝试此操作时出现错误:ORA-00904。有什么建议吗?
【问题讨论】: