本文介绍了FROM 中的子查询必须有别名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个用 PostgreSQL 编写的查询,它返回一个错误说:
I have this query I have written in PostgreSQL that returns an error saying:
[错误] 错误:
第 3 行:FROM (SELECT DISTINCT (identifiant) AS made_only_recharge
[Err] ERROR:
LINE 3: FROM (SELECT DISTINCT (identifiant) AS made_only_recharge
这是整个查询:
SELECT COUNT (made_only_recharge) AS made_only_recharge
FROM (
SELECT DISTINCT (identifiant) AS made_only_recharge
FROM cdr_data
WHERE CALLEDNUMBER = '0130'
EXCEPT
SELECT DISTINCT (identifiant) AS made_only_recharge
FROM cdr_data
WHERE CALLEDNUMBER != '0130'
)
我在 Oracle 中有一个类似的查询,它运行良好.唯一的变化是我在 Oracle 中有 EXCEPT
我用 MINUS
关键字替换了它.我是 Postgres 的新手,不知道它要求什么.处理这个问题的正确方法是什么?
I have a similar query in Oracle that works fine. The only change is where I have EXCEPT
in Oracle I have replaced it with the MINUS
key word. I am new to Postgres and don't know what it is asking for. What's the correct way of handling this?
推荐答案
在子查询中添加ALIAS
,
SELECT COUNT(made_only_recharge) AS made_only_recharge
FROM
(
SELECT DISTINCT (identifiant) AS made_only_recharge
FROM cdr_data
WHERE CALLEDNUMBER = '0130'
EXCEPT
SELECT DISTINCT (identifiant) AS made_only_recharge
FROM cdr_data
WHERE CALLEDNUMBER != '0130'
) AS derivedTable -- <<== HERE
这篇关于FROM 中的子查询必须有别名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!