0

因为标题可能很糟糕,而且我对 SQL 很薄弱,所以我将尝试澄清我的目标:

如果:

SELECT DISTINCT host, author FROM t;

好像:

foo.com | John
bar.com | Bob
bar.com | Alice

我如何获得如下结果:

foo.com | 1
bar.com | 2

如果这还不够清楚,请告诉我,我会更新或回复评论。

4

1 回答 1

2

你想要一个group by,而不是select distinct

SELECT host, count(*)
FROM t
GROUP BY host
ORDER BY count(*);

如果您可能有重复的主持人/作者组合,那么您可能需要count(distinct author)

SELECT host, count(distinct author)
FROM t
GROUP BY host
ORDER BY count(distinct author);
于 2013-09-12T00:37:22.543 回答