SQL - Advanced Window FunctionsWhich of the following is the correct syntax to calculate a running total of sales using a window function?ASELECT SUM(sales) OVER (ORDER BY date) AS running_total FROM sales_data;BSELECT SUM(sales) GROUP BY date ORDER BY running_total FROM sales_data;CSELECT RUNNING_TOTAL(sales) FROM sales_data ORDER BY date;DSELECT sales + PREVIOUS(sales) FROM sales_data;Check Answer
Step-by-Step SolutionSolution:Step 1: Identify correct window function syntaxSUM() OVER (ORDER BY column) computes running total ordered by that column.Step 2: Check other options for syntax errorsThe other options use invalid SQL syntax or functions that don't exist.Final Answer:SELECT SUM(sales) OVER (ORDER BY date) AS running_total FROM sales_data; -> Option AQuick Check:SUM() OVER (ORDER BY ...) = running total [OK]Quick Trick: Use SUM() OVER (ORDER BY ...) for running totals [OK]Common Mistakes:Using GROUP BY instead of OVER()Trying non-existent functions like RUNNING_TOTAL()Adding values manually without window syntax
Master "Advanced Window Functions" in SQL9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More SQL Quizzes Advanced Query Patterns - Finding gaps in sequences - Quiz 6medium Advanced Window Functions - Moving averages with window frames - Quiz 11easy CASE Expressions - CASE in ORDER BY - Quiz 4medium Database Design and Normalization - Second Normal Form (2NF) - Quiz 11easy Database Design and Normalization - Denormalization and when to use it - Quiz 4medium Indexes and Query Performance - Index impact on INSERT and UPDATE - Quiz 7medium Stored Procedures and Functions - Why stored procedures are needed - Quiz 14medium Stored Procedures and Functions - User-defined functions - Quiz 3easy Triggers - DELETE trigger - Quiz 12easy Window Functions Fundamentals - Window frame specification (ROWS BETWEEN) - Quiz 12easy