Skip to content

Instantly share code, notes, and snippets.

View anaibol's full-sized avatar

Anibal anaibol

View GitHub Profile
@anaibol
anaibol / asd.sql
Created October 26, 2023 18:29
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;