我有兩個表的球員和比賽:我的PSQL查看錶有什麼問題?
CREATE TABLE player(
id serial PRIMARY KEY NOT NULL,
name varchar(255) NOT NULL
);
CREATE TABLE match(
id serial PRIMARY KEY,
winner serial REFERENCES player(id) NOT NULL,
loser serial REFERENCES player(id) NOT NULL CHECK (loser != winner)
);
CREATE SEQUENCE playerid_sequence
start 1
increment 1;
CREATE SEQUENCE matchid_sequence
start 1
increment 1;
我希望創建一個連接兩個表的視圖表:
CREATE VIEW matchplayers AS
SELECT winner.name, loser.name, m.id
from player winner, player loser, match m
WHERE m.winner = winner.id AND m.loser = loser.id;
但它返回的是「名」已經提到了錯誤不止一次。相當缺乏經驗,SQL
您需要爲'name'列添加一個別名(當您沒有提供一個時,架構不會出現在Postgres爲您生成的名稱中)。使用'SELECT winner.name AS winner_name,loser.name AS loser_name,...'。 – Marth