Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Commit 474e28b

Browse files
authored
Merge pull request #593 from fbsolo/patch-29
Update count-transact-sql.md
2 parents de884b8 + 2a70891 commit 474e28b

1 file changed

Lines changed: 26 additions & 26 deletions

File tree

docs/t-sql/functions/count-transact-sql.md

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
---
1+
---
22
title: "COUNT (Transact-SQL) | Microsoft Docs"
33
ms.custom: ""
44
ms.date: "07/24/2017"
@@ -34,7 +34,7 @@ monikerRange: ">= aps-pdw-2016 || = azuresqldb-current || = azure-sqldw-latest |
3434
# COUNT (Transact-SQL)
3535
[!INCLUDE[tsql-appliesto-ss2008-all-md](../../includes/tsql-appliesto-ss2008-all-md.md)]
3636

37-
Returns the number of items in a group. COUNT works like the [COUNT_BIG](../../t-sql/functions/count-big-transact-sql.md) function. The only difference between the two functions is their return values. COUNT always returns an **int** data type value. COUNT_BIG always returns a **bigint** data type value.
37+
This function returns the number of items found in a group. `COUNT` operates like the [COUNT_BIG](../../t-sql/functions/count-big-transact-sql.md) function. These functions differ only in the data types of their return values. `COUNT` always returns an **int** data type value. `COUNT_BIG` always returns a **bigint** data type value.
3838

3939
![Topic link icon](../../database-engine/configure-windows/media/topic-link.gif "Topic link icon") [Transact-SQL Syntax Conventions](../../t-sql/language-elements/transact-sql-syntax-conventions-transact-sql.md)
4040

@@ -63,38 +63,38 @@ COUNT ( { expression | * } ) OVER ( [ <partition_by_clause> ] )
6363

6464
## Arguments
6565
**ALL**
66-
Applies the aggregate function to all values. ALL is the default.
66+
Applies the aggregate function to all values. ALL serves as the default.
6767

6868
DISTINCT
69-
Specifies that COUNT returns the number of unique nonnull values.
69+
Specifies that `COUNT` returns the number of unique nonnull values.
7070

7171
*expression*
72-
Is an [expression](../../t-sql/language-elements/expressions-transact-sql.md) of any type except **text**, **image**, or **ntext**. Aggregate functions and subqueries are not permitted.
72+
An [expression](../../t-sql/language-elements/expressions-transact-sql.md) of any type, except **image**, **ntext**, or **text**. Note that `COUNT` does not support aggregate functions or subqueries in an expression.
7373

7474
\*
75-
Specifies that all rows should be counted to return the total number of rows in a table. COUNT(\*) takes no parameters and cannot be used with DISTINCT. COUNT(\*) does not require an *expression* parameter because, by definition, it does not use information about any particular column. COUNT(*) returns the number of rows in a specified table without getting rid of duplicates. It counts each row separately. This includes rows that contain null values.
75+
Specifies that `COUNT` should count all rows to determine the total table row count to return. `COUNT(*)` takes no parameters and does not support the use of DISTINCT. `COUNT(*)` does not require an *expression* parameter because by definition, it does not use information about any particular column. `COUNT(*)` returns the number of rows in a specified table, and it preserves duplicate rows. It counts each row separately. This includes rows that contain null values.
7676

7777
OVER **(** [ *partition_by_clause* ] [ *order_by_clause* ] [ *ROW_or_RANGE_clause* ] **)**
78-
*partition_by_clause* divides the result set produced by the FROM clause into partitions to which the function is applied. If not specified, the function treats all rows of the query result set as a single group. *order_by_clause* determines the logical order in which the operation is performed. For more information, see [OVER Clause &#40;Transact-SQL&#41;](../../t-sql/queries/select-over-clause-transact-sql.md).
79-
78+
The *partition_by_clause* divides the result set produced by the `FROM` clause into partitions to which the `COUNT` function is applied. If not specified, the function treats all rows of the query result set as a single group. The *order_by_clause* determines the logical order of the operation. See [OVER Clause &#40;Transact-SQL&#41;](../../t-sql/queries/select-over-clause-transact-sql.md) for more information.
79+
8080
## Return types
8181
**int**
8282

8383
## Remarks
84-
COUNT(*) returns the number of items in a group. This includes NULL values and duplicates.
84+
COUNT(\*) returns the number of items in a group. This includes NULL values and duplicates.
8585

86-
COUNT(ALL *expression*) evaluates *expression* for each row in a group and returns the number of nonnull values.
86+
COUNT(ALL *expression*) evaluates *expression* for each row in a group, and returns the number of nonnull values.
8787

88-
COUNT(DISTINCT *expression*) evaluates *expression* for each row in a group and returns the number of unique, nonnull values.
88+
COUNT(DISTINCT *expression*) evaluates *expression* for each row in a group, and returns the number of unique, nonnull values.
8989

90-
For return values greater than 2^31-1, COUNT produces an error. Use COUNT_BIG instead.
90+
For return values exceeding 2^31-1, `COUNT` returns an error. For these cases, use `COUNT_BIG` instead.
9191

92-
COUNT is a deterministic function when used without the OVER and ORDER BY clauses. It is nondeterministic when specified with the OVER and ORDER BY clauses. For more information, see [Deterministic and Nondeterministic Functions](../../relational-databases/user-defined-functions/deterministic-and-nondeterministic-functions.md).
92+
`COUNT` is a deterministic function when used ***without*** the OVER and ORDER BY clauses. It is nondeterministic when used ***with*** the OVER and ORDER BY clauses. See [Deterministic and Nondeterministic Functions](../../relational-databases/user-defined-functions/deterministic-and-nondeterministic-functions.md) for more information.
9393

9494
## Examples
9595

9696
### A. Using COUNT and DISTINCT
97-
The following example lists the number of different titles that an employee who works at [!INCLUDE[ssSampleDBCoFull](../../includes/sssampledbcofull-md.md)] can hold.
97+
This example returns the number of different titles that an [!INCLUDE[ssSampleDBCoFull](../../includes/sssampledbcofull-md.md)] employee can hold.
9898

9999
```sql
100100
SELECT COUNT(DISTINCT Title)
@@ -111,8 +111,8 @@ GO
111111
(1 row(s) affected)
112112
```
113113

114-
### B. Using COUNT(*)
115-
The following example finds the total number of employees who work at [!INCLUDE[ssSampleDBCoFull](../../includes/sssampledbcofull-md.md)].
114+
### B. Using COUNT(\*)
115+
This example returns the total number of [!INCLUDE[ssSampleDBCoFull](../../includes/sssampledbcofull-md.md)] employees.
116116

117117
```sql
118118
SELECT COUNT(*)
@@ -129,8 +129,8 @@ GO
129129
(1 row(s) affected)
130130
```
131131

132-
### C. Using COUNT(*) with other aggregates
133-
The following example shows that `COUNT(*)` can be combined with other aggregate functions in the select list. The example uses the [!INCLUDE[ssSampleDBnormal](../../includes/sssampledbnormal-md.md)] database.
132+
### C. Using COUNT(\*) with other aggregates
133+
This example shows that `COUNT(*)` works with other aggregate functions in the `SELECT` list. The example uses the [!INCLUDE[ssSampleDBnormal](../../includes/sssampledbnormal-md.md)] database.
134134

135135
```sql
136136
SELECT COUNT(*), AVG(Bonus)
@@ -149,7 +149,7 @@ GO
149149
```
150150

151151
### D. Using the OVER clause
152-
The following example uses the MIN, MAX, AVG and COUNT functions with the OVER clause to provide aggregated values for each department in the `HumanResources.Department` table in the [!INCLUDE[ssSampleDBnormal](../../includes/sssampledbnormal-md.md)] database.
152+
This example uses the `MIN`, `MAX`, `AVG` and `COUNT` functions with the `OVER` clause, to return aggregated values for each department in the [!INCLUDE[ssSampleDBnormal](../../includes/sssampledbnormal-md.md)] database `HumanResources.Department` table.
153153

154154
```sql
155155
SELECT DISTINCT Name
@@ -194,7 +194,7 @@ Tool Design 8.62 29.8462 23.505
194194
## Examples: [!INCLUDE[ssSDWfull](../../includes/sssdwfull-md.md)] and [!INCLUDE[ssPDW](../../includes/sspdw-md.md)]
195195

196196
### E. Using COUNT and DISTINCT
197-
The following example lists the number of different titles that an employee who works at a specific company can hold.
197+
This example returns the number of different titles that an employee of a specific company can hold.
198198

199199
```sql
200200
USE ssawPDW;
@@ -210,8 +210,8 @@ FROM dbo.DimEmployee;
210210
67
211211
```
212212

213-
### F. Using COUNT(*)
214-
The following example returns the total number of rows in the `dbo.DimEmployee` table.
213+
### F. Using COUNT(\*)
214+
This example returns the total number of rows in the `dbo.DimEmployee` table.
215215

216216
```sql
217217
USE ssawPDW;
@@ -227,8 +227,8 @@ FROM dbo.DimEmployee;
227227
296
228228
```
229229

230-
### G. Using COUNT(*) with other aggregates
231-
The following example combines `COUNT(*)` with other aggregate functions in the SELECT list. The query returns the number of sales representatives with a annual sales quota greater than $500,000 and the average sales quota.
230+
### G. Using COUNT(\*) with other aggregates
231+
This example combines `COUNT(*)` with other aggregate functions in the `SELECT` list. It returns the number of sales representatives with an annual sales quota greater than $500,000, and the average sales quota of those sales representatives.
232232

233233
```sql
234234
USE ssawPDW;
@@ -248,7 +248,7 @@ TotalCount Average Sales Quota
248248
```
249249

250250
### H. Using COUNT with HAVING
251-
The following example uses COUNT with the HAVING clause to return the departments in a company that have more than 15 employees.
251+
This example uses `COUNT` with the `HAVING` clause to return the departments of a company, each of which has more than 15 employees.
252252

253253
```sql
254254
USE ssawPDW;
@@ -270,7 +270,7 @@ Production 179
270270
```
271271

272272
### I. Using COUNT with OVER
273-
The following example uses COUNT with the OVER clause to return the number of products that are contained in each of the specified sales orders.
273+
This example uses `COUNT` with the `OVER` clause, to return the number of products contained in each of the specified sales orders.
274274

275275
```sql
276276
USE ssawPDW;

0 commit comments

Comments
 (0)