I was attempting this exercise:

**Employee\_id is the primary key for this table. Each row of this table contains the ID of each employee and their respective team.  

Write an SQL query to find the team size of each of the employees.
Return result table in any order.**

| Column Name | Type |
| --- | --- |
| employee\_id | int |
| team\_id | int |

AND I produced this solution:

```
SELECT DISTINCT 
employee_id
,COUNT(employee_id) OVER (PARTITION BY team_id ORDER BY employee_id) AS team_size

FROM employee

GROUP BY 
employee_id
,team_id

```

but this produced a weird result: {"headers": ["EMPLOYEE\_ID", "TEAM\_SIZE"], "values": [[4, 1], [5, 1], [6, 2], [1, 1], [2, 2], [3, 3]]}...
then I removed the `ORDER BY employee_id` and then the output was as expected.

Now, I understand how PARTITION BY works in that it's counting number of employees per team but I thought ORDER BY only does ordering within the team. So how could it be that an order by is changing the output if all the employees are to be counted within the team regardless of the ordering?