Skip to content

Instantly share code, notes, and snippets.

@spinningcat
Created October 24, 2024 12:58
Show Gist options
  • Save spinningcat/b25d7b75292082ab0ab50d9bc998c989 to your computer and use it in GitHub Desktop.
Save spinningcat/b25d7b75292082ab0ab50d9bc998c989 to your computer and use it in GitHub Desktop.
WITH CTE_SportAttributes AS (
SELECT
st.*,
str."SportId"
FROM "dbo"."SportAttributes" AS st
INNER JOIN "dbo"."SportAttributesRelation" AS str
ON st."Id" = str."AttributeId"
),
CTE_SportAttributeGroups AS (
SELECT
sag.*,
sagr."SportId"
FROM "dbo"."SportAttributeGroups" AS sag
INNER JOIN "dbo"."SportAttributeGroupsRelation" AS sagr
ON sag."Id" = sagr."AttributeGroupId"
)
SELECT *
FROM CTE_SportAttributes AS sa
INNER JOIN CTE_SportAttributeGroups AS sag
ON sa."SportId" = sag."SportId"
INNER JOIN "dbo"."Sports" as s
ON s."Id" = sa."SportId";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment