FAANG Stock Price Extremes
Robinhood ☯️ Medium SQL
Beginner Mode

Objective

Write a SQL query to display the month-year with the highest and lowest opening prices for each stock, along with the corresponding open prices.

Table Schema:

  • stock_prices
Column Type Description
ticker VARCHAR Stock ticker symbol (e.g., 'AAPL', 'AMZN', 'GOOG', 'META', 'NFLX')
date DATE Trading date
open DECIMAL Opening price for the day
close DECIMAL Closing price for the day

Task Requirements:

  • For each stock ticker, identify the record with the highest opening price and the record with the lowest opening price
  • Extract the month and year from the date for both the highest and lowest records
  • Display both extremes in a single row per ticker
  • Format the month-year as Mon-YYYY (e.g., Jan-2022)
  • Sort the results by ticker in ascending order

Output columns: ticker, highest_month, highest_open, lowest_month, lowest_open

Examples

Example 1:

Input:

stock_prices
closedateopenticker
1722022-01-15170.5AAPL
1372022-06-20135.75AAPL
1502022-11-10148.3AAPL
1672022-03-05165.2AMZN
1402022-08-12138.5AMZN
972022-12-0195.4AMZN
1452022-02-18142.8GOOG
1102022-07-22108.65GOOG
982022-10-3096.2GOOG

Output:
highest_monthhighest_openlowest_monthlowest_openticker
Jan-2022170.5Jun-2022135.75AAPL
Mar-2022165.2Dec-202295.4AMZN
Feb-2022142.8Oct-202296.2GOOG
Quick Solution

Code Environment

Sign in or try as guest to run your code.

Sign In

Track

Question Difficulty Company Access
Need more practice in this area? Explore more questions →