SELECT DISTINCT和ORDER BY相同值的数量

时间:2016-02-23 14:41:54

标签: sql-server sql-order-by distinct

我的代码:执行此类功能需要哪些功能?

SELECT DISTINCT word
FROM Table
ORDER BY ??? -- number of equal words in descending order

示例:我有以下数据

Word
----
are
are
are
we
we
we
we
is
is
you

期望的输出:(运行查询后)

Word
----
we
are
is
you

1 个答案:

答案 0 :(得分:5)

您应该使用GROUP BY然后使用ORDER

SELECT word
FROM Table
GROUP BY Word
ORDER BY COUNT(*) DESC