我想将别名(其中有空格)与WHERE子句中的空格进行比较。
select r.resortid, sum(b.adultcount+b.childcount) as "Total Guest"
from resort r, booking b
where r.resortid = b.resortid and "Total Guest" <= 10
group by r.resortid
order by r.resortid;
我得到的错误是:
where r.resortid=b.resortid and "Total Guest" <=10
*
ERROR at line 3:
ORA-00904: "Total Guest": invalid identifier
最佳答案
Having
,而不是where
;同样,JOIN
不会造成任何伤害。
select r.resortid,
sum(b.adultcount + b.childcount) as "Total Guest"
from resort r join booking b on r.resortid = b.resortid
group by r.resortid
having sum(b.adultcount + b.childcount) <= 10
order by r.resortid;
关于sql - 如何在WHERE子句中引用列别名,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/61558522/