Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
因为标题可能很糟糕,而且我对 SQL 很薄弱,所以我将尝试澄清我的目标:
如果:
SELECT DISTINCT host, author FROM t;
好像:
foo.com | John bar.com | Bob bar.com | Alice
我如何获得如下结果:
foo.com | 1 bar.com | 2
如果这还不够清楚,请告诉我,我会更新或回复评论。
你想要一个group by,而不是select distinct:
group by
select distinct
SELECT host, count(*) FROM t GROUP BY host ORDER BY count(*);
如果您可能有重复的主持人/作者组合,那么您可能需要count(distinct author):
count(distinct author)
SELECT host, count(distinct author) FROM t GROUP BY host ORDER BY count(distinct author);