Question: Consider an SQL query that has a Window function with an ORDER BY inside the OVER clause, and an ORDER BY in the main query

Consider an SQL query that has a Window function with an ORDER BY inside the OVER clause, and an ORDER BY in the main query like this:
SELECT product_id, sale_date, amount_sold, SUM(amount_sold) OVER (PARTITION BY product_id ORDER BY sale_date) AS total_sales
FROM sales
ORDER BY product_id, sale_date;
Consider an SQL query that has a Window function with an ORDER BY inside the OVER clause, and an ORDER BY in the main query like this:
SELECT product_id, sale_date, amount_sold, SUM(amount_sold) OVER (PARTITION BY product_id ORDER BY sale_date) AS total_sales
FROM sales
ORDER BY product_id, sale_date;
The query will be illegal
The main ORDER BY will be executed first
The ORDER BY inside the OVER clause will be executed first
None of the above

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!