Skip to content

Instantly share code, notes, and snippets.

@anaibol
Created October 26, 2023 18:29
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 anaibol/f692a20d13e9bd85fec91ea34344a4b2 to your computer and use it in GitHub Desktop.
Save anaibol/f692a20d13e9bd85fec91ea34344a4b2 to your computer and use it in GitHub Desktop.
Get products per keyword count
SELECT k.name AS keyword, COUNT(kp."B") AS count
FROM "Keyword" k
LEFT JOIN (
SELECT DISTINCT "A" AS keywordId, "B"
FROM "_KeywordToProduct" -- Replace with the actual name of your intermediary table
) AS kp ON k.id = kp.keywordId
GROUP BY k.name
ORDER BY count DESC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment