1
我無法讓PostgreSQL識別匹配表爲空,因此應在下面的視圖中爲勝利和匹配列輸出0。相反,我一直在空洞的看法。當我得到一個「玩家ID」,「玩家ID」,0,每行0。可能是什麼問題呢?PostgreSQL:如果表存在返回函數其他0在視圖中
CREATE VIEW player_standings AS
SELECT
players.id,
players.name,
CASE WHEN EXISTS (SELECT * FROM matches) THEN COUNT(matches.winner) ELSE 0 END AS wins,
CASE WHEN EXISTS (SELECT * FROM matches) THEN COUNT(matches.winner) + COUNT(matches.loser) ELSE 0 END AS matches
FROM players
INNER JOIN matches
ON players.id = matches.winner
GROUP BY players.id
ORDER BY
wins DESC;
有道理!謝謝! – KishB87