认为这将是:
-- 6 degrees of separation
SELECT player_id, ps.player_state, ps.email, ph.create_date
FROM game.phone_hashes ph
INNER JOIN game.customer_settings cs ON cs.id = ph.player_id
WHERE hash IN
(SELECT hash FROM game.phone_hashes
WHERE hash IN
(SELECT hash FROM game.phone_hashes
WHERE hash IN
(SELECT hash FROM game.phone_hashes
WHERE hash IN
(SELECT hash FROM game.phone_hashes
WHERE hash IN
(SELECT hash FROM game.phone_hashes
WHERE hash IN
(SELECT hash FROM game.phone_hashes
WHERE player_id = $1))))));
请参见下面的工作方式:
-- 1 degree of separation
SELECT player_id, ps.player_state, ps.email, ph.create_date
FROM game.phone_hashes ph
INNER JOIN game.customer_settings cs ON cs.id = ph.player_id
WHERE hash IN
(SELECT hash FROM game.phone_hashes WHERE player_id = $1);
-- 2 degrees of separation
SELECT player_id, ps.player_state, ps.email, ph.create_date
FROM game.phone_hashes ph
INNER JOIN game.customer_settings cs ON cs.id = ph.player_id
WHERE hash IN
(SELECT hash FROM game.phone_hashes
WHERE hash IN
(SELECT hash FROM game.phone_hashes
WHERE player_id = $1));
-- 3 degrees of separation
SELECT player_id, ps.player_state, ps.email, ph.create_date
FROM game.phone_hashes ph
INNER JOIN game.customer_settings cs ON cs.id = ph.player_id
WHERE hash IN
(SELECT hash FROM game.phone_hashes
WHERE hash IN
(SELECT hash FROM game.phone_hashes
WHERE hash IN
(SELECT hash FROM game.phone_hashes
WHERE player_id = $1)));
-- 4 degrees of separation
SELECT player_id, ps.player_state, ps.email, ph.create_date
FROM game.phone_hashes ph
INNER JOIN game.customer_settings cs ON cs.id = ph.player_id
WHERE hash IN
(SELECT hash FROM game.phone_hashes
WHERE hash IN
(SELECT hash FROM game.phone_hashes
WHERE hash IN
(SELECT hash FROM game.phone_hashes
WHERE hash IN
(SELECT hash FROM game.phone_hashes
WHERE player_id = $1))));
-- 5 degrees of separation
SELECT player_id, ps.player_state, ps.email, ph.create_date
FROM game.phone_hashes ph
INNER JOIN game.customer_settings cs ON cs.id = ph.player_id
WHERE hash IN
(SELECT hash FROM game.phone_hashes
WHERE hash IN
(SELECT hash FROM game.phone_hashes
WHERE hash IN
(SELECT hash FROM game.phone_hashes
WHERE hash IN
(SELECT hash FROM game.phone_hashes
WHERE hash IN
(SELECT hash FROM game.phone_hashes
WHERE player_id = $1)))));
-- 6 degrees of separation
SELECT player_id, ps.player_state, ps.email, ph.create_date
FROM game.phone_hashes ph
INNER JOIN game.customer_settings cs ON cs.id = ph.player_id
WHERE hash IN
(SELECT hash FROM game.phone_hashes
WHERE hash IN
(SELECT hash FROM game.phone_hashes
WHERE hash IN
(SELECT hash FROM game.phone_hashes
WHERE hash IN
(SELECT hash FROM game.phone_hashes
WHERE hash IN
(SELECT hash FROM game.phone_hashes
WHERE hash IN
(SELECT hash FROM game.phone_hashes
WHERE player_id = $1))))));
请编辑您的问题,并添加定义('create table')所涉及的表格。 –
此外,它往往有助于理解这个问题,如果这个问题了一个例子 - 数据的几行,什么查询的结果应基于此样本数据。 –
A **表定义**就是你'在psql的\ d game.phone_hashes'得到。或完整的CREATE TABLE脚本。 –