如何在不合并 SQL 服务器中的行的情况下创建一个显示另一列中的值出现次数的列

How to create a column that shows the number of times a value in another column appears without combining rows in SQL Server

我有一个如下所示的数据库:

+----------------+
| Account Number | 
+----------------+
| A0001          |
| A0001          |
| A0001          |
| A0002          |
| A0003          |
| A0003          |
+----------------+

我需要在不更改行数的情况下创建一个包含帐号出现次数的列。

我知道

SELECT Account Number, COUNT(*) AS Counts
FROM database
GROUP BY Account Number

returns

+----------------+--------+
| Account Number | Counts |
+----------------+--------+
| A0001          | 3      |
| A0002          | 1      |
| A0003          | 2      |
+----------------+--------+

但我需要这样的东西:

+----------------+--------+
| Account Number | Counts |
+----------------+--------+
| A0001          | 3      |
| A0001          | 3      |
| A0001          | 3      |
| A0002          | 1      |
| A0003          | 2      |
| A0003          | 2      |
+----------------+--------+

我正在使用 Microsoft SQL 服务器。

您可以在此处将计数用作 window function

Select AccountNumber, 
 count(*) over (partition by AccountNumber) as counts
from Table