Given 3 columns (sid, date, tid) and primary key (date, tid). Find the sids that have every tid

It should serve your purpose.

WITH cdata AS (
    SELECT 
        sid, 
        count(DISTINCT tid) tid_count 
    FROM winners 
    GROUP BY sid
)
SELECT 
    sid 
FROM cdata 
WHERE 
    tid_count = (SELECT max(tid_count) FROM cdata)

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top