内部結合ステートメントを使用して 2 つのテーブルから情報を取得する SQL ビューを作成しようとしていますが、理解できないエラーが発生し続けます。私が作成しようとしているビュー ステートメントは、名、姓、および pid (テーブルをリンクするために使用されるもの) を取得し、体重が 140 ポンドを超える人々のみを表示します。psql で 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);
私が使用している2つのテーブルは
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