今天在用Oracle写sql的时候一直报错,来回折腾了一番还是不行,开始怀疑自己的知识认知了。
Oracle中 having 语句后面不能使用别名。
例子:
- 报错写法(ORA-00904: "NUM": invalid identifier)
select count(*) as num,xxx from table group by xxx HAVING num>1;
- 正确写法
select count(*) as num,xxx from table group by xxx HAVING count(*)>1;
ps:查看Oracle版本
select * from v$version;