Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

SQL question: Write a SQL query that gets each month's rolling sum of the transaction amount for each store over the past year. An example

SQL question:

Write a SQL query that gets each month's rolling sum of the transaction amount for each store over the past year.

An example of the original table (table name is "t1") should look like this, it should contain hundreds of store IDs instead of just ABCD:

image text in transcribed

The expected result should look like this, I only included store A and store B here for convenience, but the result should contain all stores:

image text in transcribed

Thank you!!!

StorelD Date monthly_amt A 201901 100 C 201908 700 A 201902 105 A 201902 66 A 201903 99 A 201904 180 D 201906 200 A 201905 300 A 201905 200 A 201906 700 A 201907 58 A 201907 32 A 201907 900 A 201908 4500 A 201909 80 201910 500 A 201911 700 A 201912 60 B 201901 777 B 201902 109 B 201903 400 B 201904 700 B 201905 500 B 201906 300 B 201906 300 B 201907 99 B 201908 66 B 201909 300 B 201910 507 B 201911 7900 B 201912 500 StoreID Date monthly_amt Rolling Sum A 201901 100 100 201902 171 271 A 201903 99 370 201904 180 550 201905 500 1050 A 201906 700 1750 A 201907 990 2740 A 201908 4500 7240 A 201909 80 7320 A 201910 500 7820 A 201911 700 8520 A 201912 60 8580 B 201901 777 777 B 201902 109 886 B 201903 400 1286 B 201904 700 1986 B 201905 500 2486 B 201906 600 3086 B 201907 99 3185 B 201908 66 3251 B 201909 300 3551 B 201910 507 4058 B 201911 7900 11958 B 201912 500 12458

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

10th Edition

0137916787, 978-0137916788

More Books

Students also viewed these Databases questions

Question

Evaluate 3x - x for x = -2 Answer:

Answered: 1 week ago

Question

What is group replacement? Explain with an example. (2-3 lines)

Answered: 1 week ago

Question

6. What questions would you suggest should be included?

Answered: 1 week ago