【问题标题】:postgresql return table ERROR: column reference is ambiguouspostgresql 返回表错误:列引用不明确
【发布时间】:2016-08-12 12:19:43
【问题描述】:

我正在尝试在 R 中运行查询以检查两个不同子版块之间的共享评论者。但是,我不断收到以下错误:

警告:postgresqlExecStatement 中的错误:RS-DBI 驱动程序:(无法检索结果:错误:列引用“subreddit”不明确 )

任何想法我哪里出错了?

query <- sprintf("
SELECT final.subreddit_a, final.subreddit_b 
FROM 
  (SELECT a.subreddit AS subreddit_a, 
          a.authors AS authors_in_sub_a, 
          b.subreddit AS subreddit_b, 
          b.authors AS authors_in_sub_b, 
          floor(100 * (count(*)/((a.authors + b.authors)/2))) AS percentage 
  FROM
    (SELECT t1.author AS author, 
            t1.subreddit AS subreddit, 
            t2.authors AS authors
    FROM 
      (SELECT DISTINCT author, subreddit 
      FROM %s 
      WHERE %s author!='[deleted]') AS t1
      JOIN 
        (SELECT * 
        FROM 
          (SELECT subreddit, count(distinct author) AS authors 
          FROM %s 
          WHERE %s author!='[deleted]' GROUP BY subreddit) AS t5 
          WHERE authors >= %s) AS t2
      ON t1.subreddit=t2.subreddit
      GROUP BY subreddit, author) AS a
    JOIN 
      (SELECT t3.author AS author, 
              t3.subreddit AS subreddit, 
              t4.authors AS authors
      FROM 
        (SELECT DISTINCT author, subreddit 
        FROM %s 
        WHERE %s author!='[deleted]') AS t3
        JOIN 
          (SELECT * 
          FROM 
            (SELECT subreddit, count(distinct author) AS authors 
            FROM %s 
            WHERE %s author!='[deleted]' GROUP BY subreddit) AS t6 
          WHERE authors >= %s) AS t4
        ON t3.subreddit=t4.subreddit
        GROUP BY subreddit, author) AS b
      ON a.author=b.author
    WHERE a.subreddit!=b.subreddit GROUP BY 1,3) AS final
  WHERE final.percentage > %s;"

【问题讨论】:

标签: postgresql return ambiguous


【解决方案1】:

table_name.subreddit 而不是subreddit

【讨论】:

    【解决方案2】:

    您应该在长选择查询的表名上使用别名

    【讨论】:

      猜你喜欢
      • 2012-05-31
      • 2018-01-26
      • 1970-01-01
      • 2023-01-18
      • 2012-04-06
      • 2015-01-07
      • 2018-07-02
      • 1970-01-01
      • 2021-01-08
      相关资源
      最近更新 更多