Last answered:

25 Oct 2023

Posted on:

12 Oct 2023


Resolved: Redundant Group by clause

As the aggregate function (AVG) is used in the context of window function, so we dont need to use the GROUP BY clause in the query. Both in the video example and in the solution, group by clause has been used in the main query. I have tried running query without the group by clause and it returns the same output. Please advise.



1 answers ( 1 marked as helpful)
Posted on:

25 Oct 2023


Hi Tanika!
Thanks for reaching out.

Yes, when using aggregate functions as window functions with an `OVER()` clause, there's no need to use the `GROUP BY` clause in the main query to partition the data. The window function can handle the partitioning and ordering on its own. The reason the `GROUP BY` clause is used is for illustrative purposes. If your query without the `GROUP BY` clause produces the desired results, then it's correct for your specific use case.

Hope this helps.

Submit an answer