现在,您已经进一步详细说明了您实际想要实现的目标,可以看出该问题要复杂得多。你真正想要的所有组合
subscriber_id和
tag_id,再算上在连接表产品实际的条目数。。所以这是SQL:
SELECt combinations.tag_id, combinations.subscriber_id,-- correlated subquery to count the actual hits by tag/subscriber when joining-- the two tables using content_id (SELECT count(*) FROM content_hits AS h JOIN content_tag AS t ON h.content_id = t.content_id WHERe h.subscriber_id = combinations.subscriber_id AND t.tag_id = combinations.tag_id) as cnt-- Create all combinations of tag/subscribers first, before counting anything-- This will be necessary to have "zero-counts" for any combination of-- tag/subscriberFROM ( SELECt DISTINCT tag_id, subscriber_id FROM content_tag CROSS JOIN content_hits) AS combinations



