今天在用Oracle寫sql的時候一直報錯,來回折騰了一番還是不行,開始懷疑自己的知識認(rèn)知了。
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;

result.jpg