且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我如何使用 T-SQL Group By

更新时间:2023-02-05 23:33:23

要从具有 5 个以上小部件的每个小部件类别中检索小部件的数量,您可以执行以下操作:

To retrieve the number of widgets from each widget category that has more than 5 widgets, you could do this:

SELECT WidgetCategory, count(*)
FROM Widgets
GROUP BY WidgetCategory
HAVING count(*) > 5

人们经常忘记have"子句,而是选择将所有数据检索到客户端并在那里迭代.

The "having" clause is something people often forget about, instead opting to retrieve all their data to the client and iterating through it there.