内部联接参考

时间:2017-07-10 09:49:53

标签: postgresql

在进行内部连接时,我无法引用两列。我尝试了以下组合无济于事。

SELECT
*
FROM
adwords_final
INNER JOIN mk_kw ON adwords_final.Key = mk_kw.Key;

SELECT
*
FROM
adwords_final
INNER JOIN mk_kw ON "adwords_final.Key" = "mk_kw.Key";

导致以下或类似的东西。

ERROR:  column adwords_final.key does not exist
LINE 5: INNER JOIN mk_kw ON adwords_final.Key = mk_kw.Key;
                        ^
HINT:  Perhaps you meant to reference the column "adwords_final.Key".
********** Error **********

ERROR: column adwords_final.key does not exist
SQL state: 42703
Hint: Perhaps you meant to reference the column "adwords_final.Key".
Character: 49

在我看来,我错过了一些更明显的东西。我是否需要进一步引用后者或完全创建新查询?

由于

adwords final中的列;

Week    Keyword state   Keyword Campaign    Ad group    Status  Max. CPC    Impressions Interactions    Interaction Types   Interaction Rate    Avg. Cost   Cost    Clicks  Avg. position   Conversions Quality score   Ad relevance    Landing page experience Expected clickthrough rate  Qual. score (hist.) Ad relevance (hist.)    Landing page experience (hist.) Expected clickthrough rate (hist.)  Search Impr. share  Match type  First position CPC  Top of page CPC First page CPC  Impressions with average ctr    Impressions with above average ctr  Impressions with below average ctr  Impressions with below average lp exp   Impressions with average lp exp Impressions with above average lp exp   Impressions with below average Ad Rel   Impressions with  average ad rel    Impressions with above average ad rel   QSxIMP  Key

mk_kw中的列

 Language   Network Main Keyword    Cluster Keyword 1   Match Type  Key

1 个答案:

答案 0 :(得分:1)

标识符的每个元素都需要用双引号括起来。不是完整的标识符。

所以你需要使用:

"adwords_final"."Key"代替"adwords_final.Key"

"mk_kw"."Key"代替"mk_kw.Key"

请注意,不需要引用全部小写的标识符。 "mk_kw"."Key"mk_kw."Key"

相同

有关完整说明,请参阅手册中的Identifiers and Key Words一章。