Calculating cumulative sales with windowing functions

InterviewQs

Calculating cumulative sales with windowing functions

SQL Database Querying Window Function Cumulative Sum Subquery

Forward this email to a friend or colleague and challenge them to solve it.

Hi, 

Suppose you are given the following table showing company sales:

Table: sales_info

date sale_id sale_usd
2020-01-05 1111 93695
2020-01-07 1112 879617
2020-01-07 1113 752878
... ... ...

Calculate the cumulative percent of total sales on a given day. Cumulative sales up to a day is calculated adding the total sales of the current day and adding all the prior day total sales. The total sales can be calculated by adding all sales that exist in the table. To get the percent of cumulative total sales, you will need to calculate the cumulative sales and divide by the total sales. The output of the table should look like the example table below.

date pct_total_sales
2020-01-05 X.XX
2020-01-07 Y.YY

You can view/query the data in an interactive SQL fiddle here.



 

You’ve accumulated 373 questions since joining our email list. Create a premium account to access detailed solutions to each problem (including this one) + our new Case studies.


Was this email forwarded to you? You can join our list here to receive questions

How did you like today's question?

15411 Boischatel, Montreal, QC, H9H1Y7, Canada
Don't want to get these emails anymore? We'll forgive you if you unsubscribe

Key phrases

Older messages

Setting up a custom alert system for changes to a URL

Wednesday, November 16, 2022

Python, Data Structures, External Dataset, InterviewQs Setting up a custom alert system for changes to a URL Python Data Structures External Dataset Forward this email to a friend or colleague and

Calculating the Root Mean Squared Error (RMSE) of a model

Monday, November 14, 2022

Python, Data Structures, RMSE, Arrays, InterviewQs Calculating the Root Mean Squared Error (RMSE) of a model Python Data Structures RMSE Arrays Forward this email to a friend or colleague and challenge

Precision, recall, and F-1 scores

Friday, November 11, 2022

Precision, Recall, F1 Score, Machine Learning, InterviewQs Precision, recall, and F-1 scores Precision Recall F1 Score Machine Learning Forward this email to a friend or colleague and challenge them to

Moving average trading strategy

Thursday, November 10, 2022

SQL, Database Querying, Window Function, Subquery, InterviewQs Moving average trading strategy SQL Database Querying Window Function Subquery Forward this email to a friend or colleague and challenge

Selecting computers for a company

Monday, November 7, 2022

Data Analysis, Python, Pandas, Data Manipulation, Data Visualization, External Dataset, Case Study, InterviewQs Selecting computers for a company Data Analysis Python Pandas Data Manipulation Data

SBF says he's 'had a bad month,' but is he really giving us the full story?

Thursday, December 1, 2022

TechCrunch Newsletter TechCrunch logo The Daily Crunch logo By Christine Hall and Haje Jan Kamps Thursday, December 01, 2022 There is officially only 8.3% left of the year. You know what that means!

FTX’s collapse was a crime, not an accident — TSMC to make 4nm chips in Arizona for Apple, AMD, Nvidia — and Apple blocks Coinbase Wallet

Thursday, December 1, 2022

Issue #968 — Top 20 stories of December 02, 2022 Issue #968 — December 02, 2022 You receive this email because you are subscribed to Hacker News Digest. You can open it in the browser if you prefer. 1

Daily Coding Problem: Problem #952 [Easy]

Thursday, December 1, 2022

Daily Coding Problem Good morning! Here's your coding interview problem for today. This problem was asked by Slack. You are given a string formed by concatenating several words corresponding to the

💎 Issue 341 - Crystal For Rubyists

Thursday, December 1, 2022

This week's Awesome Ruby Newsletter Read this email on the Web The Awesome Ruby Newsletter Issue » 341 Release Date Dec 01, 2022 Your weekly report of the most popular Ruby news, articles and

💻 Issue 341 - TIL – How to split JavaScript strings into sentences, words or graphemes with Intl.Segmenter

Thursday, December 1, 2022

This week's Awesome JavaScript Weekly Read this email on the Web The Awesome JavaScript Weekly Issue » 341 Release Date Dec 01, 2022 Your weekly report of the most popular JavaScript news, articles

📱 Issue 335 - What are your thoughts on this thread? “Stop using MVVM for SwiftUI”

Thursday, December 1, 2022

This week's Awesome iOS Weekly Read this email on the Web The Awesome iOS Weekly Issue » 335 Release Date Dec 01, 2022 Your weekly report of the most popular iOS news, articles and projects Popular

💻 Issue 334 - Announcing ML.NET 2.0

Thursday, December 1, 2022

This week's Awesome .NET Weekly Read this email on the Web The Awesome .NET Weekly Issue » 334 Release Date Dec 01, 2022 Your weekly report of the most popular .NET news, articles and projects

Data Science Weekly - Issue 471

Thursday, December 1, 2022

Curated news, articles and jobs related to Data Science. Keep up with all the latest developments Email not displaying correctly? View it in your browser. Issue #471 December 01 2022 Editor's Picks

💻 Issue 341 - Node.js visualized: promise, async/await and process.nextTick under the hood

Thursday, December 1, 2022

This week's Awesome Node.js Weekly Read this email on the Web The Awesome Node.js Weekly Issue » 341 Release Date Dec 01, 2022 Your weekly report of the most popular Node.js news, articles and

💻 Issue 259 - React Conditional Rendering With Type Safety and Exhaustive Checking

Thursday, December 1, 2022

This week's Awesome React Weekly Read this email on the Web The Awesome React Weekly Issue » 259 Release Date Dec 01, 2022 Your weekly report of the most popular React news, articles and projects