如何获得不不同的值(计算> 1)

时间:2021-11-21 15:33:13

I'm trying (in SQL Server 2k8) to get a list of TheField where TheField exists more than once. Something like the following (except I know this isn't right):

我正在尝试(在SQL Server 2k8中)获取字段存在不止一次的字段列表。如下所示(但我知道这不对):

SELECT TheField FROM TheTable WHERE COUNT(TheField) > 1

2 个解决方案

#1


4  

You can use GROUP BY with HAVING clause:

您可以使用GROUP BY with have clause:

SELECT TheField, COUNT(*) AS Count
FROM TheTable 
GROUP BY TheField
HAVING COUNT(*) > 1

Specifies a search condition for a group or an aggregate. HAVING can be used only with the SELECT statement. HAVING is typically used in a GROUP BY clause. When GROUP BY is not used, HAVING behaves like a WHERE clause.

指定组或聚合的搜索条件。have只能与SELECT语句一起使用。具有通常在GROUP BY子句中使用。当不使用GROUP BY时,具有类似WHERE子句的行为。

#2


1  

Use the HAVING clause:

使用条款:

SELECT TheField 
FROM TheTable 
GROUP BY TheField
HAVING COUNT(TheField) > 1

#1


4  

You can use GROUP BY with HAVING clause:

您可以使用GROUP BY with have clause:

SELECT TheField, COUNT(*) AS Count
FROM TheTable 
GROUP BY TheField
HAVING COUNT(*) > 1

Specifies a search condition for a group or an aggregate. HAVING can be used only with the SELECT statement. HAVING is typically used in a GROUP BY clause. When GROUP BY is not used, HAVING behaves like a WHERE clause.

指定组或聚合的搜索条件。have只能与SELECT语句一起使用。具有通常在GROUP BY子句中使用。当不使用GROUP BY时,具有类似WHERE子句的行为。

#2


1  

Use the HAVING clause:

使用条款:

SELECT TheField 
FROM TheTable 
GROUP BY TheField
HAVING COUNT(TheField) > 1