Problem with Analysing Variations

Easy
14
41.9% Acceptance

Juan was attempting to solve a aggregation function queries and seem to have hit a roadblock with the challenge. Can you take a look at the query written by Juan and find out the reasoning for the bugs and fix them. The below is are the Instructions for the challenge Juan was attempting to solve.


For each day, compute the total number of admissions. Additionally, calculate the difference in the number of admissions from the previous day.

Concepts to understand:

  • Aggregate Functions: These are SQL functions that perform a calculation on a set of values and return a single value. Examples include SUM(), COUNT(), AVG(), etc.

  • Window Functions: These are special SQL functions that perform calculations across a set of rows related to the current row. An example in this exercise would be LAG(), which can fetch data from a previous row.

Your goal is to write an SQL query that accomplishes the given task. Remember, focus on the structure of your query, the use of aggregate functions, and the application of window functions where necessary. Good luck!