Skip to content

Instantly share code, notes, and snippets.

@fulmicoton
Created April 25, 2022 01:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fulmicoton/0966649e893adf6c607ac119d9c0c15b to your computer and use it in GitHub Desktop.
Save fulmicoton/0966649e893adf6c607ac119d9c0c15b to your computer and use it in GitHub Desktop.
WITH
poss AS (
SELECT x, y, x*y AS p, x+y as s
FROM
GENERATE_SERIES(2,100) as x,
GENERATE_SERIES(2,100) as y
WHERE x + y <= 100 AND y > x
),
poss_after_sue_2 AS (
SELECT *
FROM poss
WHERE poss.s NOT IN (
SELECT poss.s
FROM poss
WHERE poss.p IN (
SELECT p
FROM poss
GROUP BY p
HAVING COUNT(*) = 1
)
)
),
poss_after_pete3 AS (
SELECT *
FROM poss_after_sue_2
WHERE p IN (
SELECT p
FROM poss_after_sue_2
GROUP BY p
HAVING COUNT(*) = 1
)
)
SELECT x, y
FROM poss_after_pete3
WHERE s in (
SELECT s
FROM poss_after_pete3
GROUP BY s
HAVING COUNT(*) = 1
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment