Yes, we can use an aggregate function as a window function by using the OVER clause. The aggregate function will reduce the number of rows or records since they perform the calculation of a set of row values to return a single value. Whereas the window function does not reduce the number of records.


Let's assume the table below to explain the aggregate function then we will be going to use the aggregate function as a window function:


Table Name: Manager

id name salary
1 Jeff 8000
2 Elon 5000
3 Mukesh 5000
4 Warren 4000
5 Bill 3000


The query for aggregate function:

SELECT SUM(salary) as total_salary FROM manager;


total_salary
24000


Let's implement the aggregate function as a window function:

SELECT SUM(salary) OVER()  as total_salary FROM manager;


total_salary
24000
24000
24000
24000
24000

Using SUM as a window function (with the OVER clause) does not reduce the no of records. Please note it’s not mandatory to use ORDER BY or PARTITION BY inside the OVER clause as shown here.