WITH e1 AS (
  -- Erdos number is 1
  SELECT DISTINCT b.author
  FROM auth AS a
    -- same paper, but different author
    JOIN auth AS b ON a.dblp_key = b.dblp_key
                   AND a.author != b.author
  WHERE a.author = 'Paul Erdös'
)
-- Erdos number is 2
SELECT DISTINCT d.author
FROM e1
  -- first get all papers of e1 authors
  JOIN auth AS c ON e1.author = c.author
  -- same paper, but different author
  JOIN auth AS d ON c.dblp_key = d.dblp_key
                   AND c.author != d.author
-- excluding e0 and e1
WHERE d.author != 'Paul Erdös'
  AND d.author NOT IN (SELECT author FROM e1);
