[英]Oracle SQL: invalid identifier
誰能向我解釋為什么dLoad在GROUP BY行中是無效標識符? 這在Mysql上運行良好,但我無法使其與Oracle一起使用。
CREATE OR REPLACE VIEW DoctorsLoad AS
SELECT dID, gender, specialty, 'Overloaded' AS dLoad
FROM Doctor D, Examine E
WHERE D.dID = E.doctor_id
GROUP BY dID, gender, specialty, dLoad
HAVING COUNT(*) > 10
UNION
SELECT dID, gender, specialty, 'Underloaded' AS dLoad
FROM Doctor D, Examine E
WHERE D.dID = E.doctor_id
GROUP BY dID, gender, specialty, dLoad
HAVING COUNT(*) <= 10;
使用Oracle RDMS,您不能在GROUP BY
子句中使用別名,但是對於“重載”之類的文字,無論如何您都無需將其包括在組中。
CREATE OR REPLACE VIEW DoctorsLoad AS
SELECT dID, gender, specialty, 'Overloaded' AS dLoad
FROM Doctor D, Examine E
WHERE D.dID = E.doctor_id
GROUP BY dID, gender, specialty
HAVING COUNT(*) > 10
UNION ALL
SELECT dID, gender, specialty, 'Underloaded' AS dLoad
FROM Doctor D, Examine E
WHERE D.dID = E.doctor_id
GROUP BY dID, gender, specialty
HAVING COUNT(*) <= 10;
我還建議使用UNION ALL
,這樣可以避免執行過濾操作來刪除重復的行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.