0
내부 조인 문을 사용하여 2 개의 테이블에서 정보를 가져 오는 SQL보기를 만들려고하지만 알아낼 수없는 오류가 계속 발생합니다. 내가 만들고자하는 view 문은 이름, 성, 그리고 pid (테이블을 연결하는 데 사용되는 것)를 취한 다음 몸무게가 140 파운드 이상인 사람들 만 표시합니다. psql에서 sql 파일을 실행하려고하면 오류가 계속 발생합니다. 내가 오류가내부 조인 문을 사용하여 SQL보기 만들기
\i letsdoit.sql
output #1
psql:letsdoit.sql:7: ERROR: column reference "pid" is ambiguous
LINE 2: SELECT pid,fname, lnam
내가
\echo output #1
CREATE VIEW weight AS
SELECT a.pid, a.fname, a.lname
FROM letsdoit.person as a
INNER JOIN letsdoit.body_composition as b
ON a.pid = b.pid
WHERE (b.weight>140);
입니다 가지고있는 코드와 I는
Table "letsdoit.person"
Column | Type | Modifiers
--------+-----------------------+---------------------------------------------------
pid | integer | not null default nextval('person_pid_seq'::regclass)
uid | integer |
fname | character varying(25) | not null
lname | character varying(25) | not null
Indexes
"person_pkey" PRIMARY KEY, btree (pid)
Foreign-key constraints:
"person_uid_fkey" FOREIGN KEY (uid) REFERENCES university(uid) ON DELETE CASCADE
Referenced by:
TABLE "body_composition" CONSTRAINT "body_composition_pid_fkey" FOREIGN KEY (pid
) REFERENCES person(pid) ON DELETE CASCADE
TABLE "participated_in" CONSTRAINT "participated_in_pid_fkey" FOREIGN KEY (pid)
REFERENCES person(pid)
및
Table "letsdoit.body_composition"
Column | Type | Modifiers
--------+---------+-----------
pid | integer | not null
height | integer | not null
weight | integer | not null
age | integer | not null
Indexes:
"body_composition_pkey" PRIMARY KEY, btree (pid)
Foreign-key constraints:
"body_composition_pid_fkey" FOREIGN KEY (pid) REFERENCES person(pid) ON DELETE CASCADE
@micheal 감사합니다, 난 여전히 하나의 오류가 발생합니다. 하지만 내가 얻는 오류는 => \ i letsdoit.sql 출력 # 1 psql : letsdoit.sql : 7 : ERROR : relation "weight"가 이미 존재합니다. – disciples22
이유가 무엇입니까? – disciples22
오류가 발생한 행은 무엇입니까? – baao