두 개의 서로 다른 하위 색인 사이에 공유 된 주석 작성자를 확인하기 위해 R에서 쿼리를 실행하려고합니다. 그러나 계속해서 다음 오류가 발생합니다.postgresql return table ERROR : 열 참조가 모호합니다.
Warning: Error in postgresqlExecStatement: RS-DBI driver: (could not Retrieve the result : ERROR: column reference "subreddit" is ambiguous )
내가 잘못 가고있는 아이디어가 있습니까?
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;"
이 소스의에 쿼리에서 하위 Reddit 필드의 모든 사용을 한정 충분해야한다 긴 선택 쿼리와 테이블 이름에 별칭을 사용해야합니다. 이제는 가끔 (예 : a.subreddit) 할 수 있지만, 별명 | 테이블 이름이 없으면 최소한 몇 가지 용도가 있습니다. – rsc
가능한 [pgsql 반환 테이블 오류 : 열 참조가 모호합니다] (http://stackoverflow.com/questions/10750707/pgsql-return-table-error-column-reference-is-ambiguous) – rsc