这个 SQL 查询有什么问题?
以下查询返回“ORA-00904 错误:SATIS:标识符无效。”当我删除行 HAVING satis >; 0
,它有效。我应该怎么办?
SELECT donem, bolge_adi, sehir_tasra "1=Ş, 2=T",
COUNT(DISTINCT mekankodu) "M.SAYISI",
SUM(b2b_dagitim + b2b_transfer - b2b_iade) satis
FROM mps_view2
WHERE donem IN ('200612','200712','200812','200912')
AND (ob IS NOT NULL OR b2b_ob IS NOT NULL)
GROUP BY donem, bolge_adi, sehir_tasra
HAVING satis > 0
ORDER BY donem, bolge_adi, sehir_tasra
The following query returns "ORA-00904 error: SATIS: Invalid identifier." When I remove the line HAVING satis > 0
, it works. What should I do?
SELECT donem, bolge_adi, sehir_tasra "1=Ş, 2=T",
COUNT(DISTINCT mekankodu) "M.SAYISI",
SUM(b2b_dagitim + b2b_transfer - b2b_iade) satis
FROM mps_view2
WHERE donem IN ('200612','200712','200812','200912')
AND (ob IS NOT NULL OR b2b_ob IS NOT NULL)
GROUP BY donem, bolge_adi, sehir_tasra
HAVING satis > 0
ORDER BY donem, bolge_adi, sehir_tasra
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您不能在条件(具有查询部分)中使用别名,
请尝试以下操作:
You can not use alias in conditions (having section of your query)
try this one:
从这里:
http://download.oracle.com /docs/cd/B19306_01/server.102/b14200/statements_10002.htm
From here:
http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_10002.htm
您需要将其更改为
您不能在 HAVING 子句中使用别名。
You need to change it to
You cannot use the alias in the HAVING clause.