Data Interview Qs - Total value of trades

InterviewQs

Total value of trades

SQL Database Querying Window Function Subquery

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

Hi, 

Suppose you're given the following table showing open, high, low, and close prices for a stock on a given date (preview of the schema, full schema in link below):

Table: Prices

Date Open High Low Close
2020-01-02 00:00:00 1875 1898.01 1864.15 1898.01
2020-01-03 00:00:00 1864.5 1886.2 1864.5 1874.97
2020-01-06 00:00:00 1860 1903.69 1860 1902.88
2020-01-07 00:00:00 1904.5 1913.89 1892.04 1906.86

Given this, calculate the 20-day moving average of the closing price. Then, if the price of the day's open is greater than the 20-day moving average, you will "buy" the stock and sell on close for that day. Using this strategy, write a SQL query to calculate the total value of these trades.

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


 

You’ve accumulated 333 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

Older messages

Analyzing a locker storage system

Monday, August 15, 2022

Data Analysis, Python, Pandas, External Dataset, Data Manipulation, Data Visualization, Statistics, Probability Mass Function, InterviewQs Analyzing a locker storage system Data Analysis Python Pandas

Implementing an Elo Rating System

Friday, August 12, 2022

Python, Algorithms, Data Structures, Simulation, Elo Rating, InterviewQs Implementing an Elo Rating System Python Algorithms Data Structures Simulation Elo Rating Forward this email to a friend or

Central Limit Theorem

Friday, August 12, 2022

Statistics, Central Limit Theorem, Population Estimation, InterviewQs Central Limit Theorem Statistics Central Limit Theorem Population Estimation Forward this email to a friend or colleague and

University acceptance rates by college and program

Monday, August 8, 2022

SQL, Database Querying, Aggregation Functions, InterviewQs University acceptance rates by college and program SQL Database Querying Aggregation Functions Forward this email to a friend or colleague and

Correlation between IMBD and Rotten Tomatoes ratings

Friday, August 5, 2022

Python, Data structures, Correlation Analysis, InterviewQs Correlation between IMBD and Rotten Tomatoes ratings Python Data structures Correlation Analysis Forward this email to a friend or colleague

You Might Also Like

AI search engine startup Perplexity eyes a $3B valuation

Tuesday, April 23, 2024

Plus: It's Tesla earnings day and AWS wants to host your AI models View this email online in your browser By Cody Corrall Tuesday, April 23, 2024 Welcome back to TechCrunch PM. Today we have big

🎞️ We Tried 3D Printing a Photo — You'll Love This Secret Samsung Galaxy Bluetooth Feature

Tuesday, April 23, 2024

Also: Transferring Your Phone Number to a New Carrier, and More! How-To Geek Logo April 23, 2024 📩 Get expert reviews, the hottest deals, how-to's, breaking news, and more delivered directly to

You're invited – product sense, prioritization, careers

Tuesday, April 23, 2024

Product Sense Product Sense Wednesday, May 1st @ 01:00 PM EST Learn how to identify opportunities, assess risks, and make informed decisions that lead to successful product innovations by better

CTRL-C, Exceptions, Ruff Speed-up, and More

Tuesday, April 23, 2024

Asyncio Handle Control-C (SIGINT) #626 – APRIL 23, 2024 VIEW IN BROWSER The PyCoder's Weekly Logo Asyncio Handle Control-C (SIGINT) When the user presses CTRL-C on the keyboard, the OS raises an

Writing Contests Just Landed On Product Hunt 🔥

Tuesday, April 23, 2024

Upvote us to keep the $$$ coming! 👍 ͏ ‌  ͏ ‌  ͏ ‌  ͏ ‌  ͏ ‌  ͏ ‌  ͏ ‌  ͏ ‌ ͏ ‌  ͏ ‌  ͏ ‌  ͏ ‌  ͏ ‌  ͏ ‌  ͏ ‌  ͏ ‌ ͏ ‌  ͏ ‌  ͏ ‌  ͏ ‌  ͏ ‌  ͏ ‌  ͏ ‌  ͏ ‌ ͏ ‌  ͏ ‌  ͏ ‌  ͏ ‌ 

Daily Coding Problem: Problem #1421 [Hard]

Tuesday, April 23, 2024

Daily Coding Problem Good morning! Here's your coding interview problem for today. This problem was asked by Uber. Given an array of integers, return a new array such that each element at index i

Ranked | The Top 10 EV Battery Manufacturers 🔋

Tuesday, April 23, 2024

Asia dominates this ranking of the world's largest EV battery manufacturers in 2023. See which battery makers feature in the top 10. View Online | Subscribe Presented by: EnergyX's

Bringing PGO to the build pipeline

Tuesday, April 23, 2024

Plus how Go grew at Google, cmp.Or, and ways to visualize makefiles, Go binaries, and live Go processes. | #​504 — April 23, 2024 Unsub | Web Version Together with Three Dots Labs Go Weekly How Dolt

Noonification: Leetcode: Two-sum an Intuitive Approach

Tuesday, April 23, 2024

Top Tech Content sent at Noon! Get Algolia: AI Search that understands How are you, @newsletterest1? 🪐 What's happening in tech this week: The Noonification by HackerNoon has got you covered with

The best AI chatbot for coding

Tuesday, April 23, 2024

9 video gadget must-haves; 6 things Linux should borrow from MacOS -- ZDNET ZDNET Tech Today - US April 23, 2024 placeholder Can Meta AI code? I tested it against Llama, Gemini and ChatGPT - it wasn