FAANG Stock Price Extremes
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
tickerin ascending order
Output columns: ticker, highest_month, highest_open, lowest_month, lowest_open
Examples
Example 1:
Output:
Input:
| stock_prices | |||
|---|---|---|---|
| close | date | open | ticker |
| 172 | 2022-01-15 | 170.5 | AAPL |
| 137 | 2022-06-20 | 135.75 | AAPL |
| 150 | 2022-11-10 | 148.3 | AAPL |
| 167 | 2022-03-05 | 165.2 | AMZN |
| 140 | 2022-08-12 | 138.5 | AMZN |
| 97 | 2022-12-01 | 95.4 | AMZN |
| 145 | 2022-02-18 | 142.8 | GOOG |
| 110 | 2022-07-22 | 108.65 | GOOG |
| 98 | 2022-10-30 | 96.2 | GOOG |
| highest_month | highest_open | lowest_month | lowest_open | ticker |
|---|---|---|---|---|
| Jan-2022 | 170.5 | Jun-2022 | 135.75 | AAPL |
| Mar-2022 | 165.2 | Dec-2022 | 95.4 | AMZN |
| Feb-2022 | 142.8 | Oct-2022 | 96.2 | GOOG |
Code Environment
Sign in or try as guest to run your code.
Track
| Question | Difficulty | Company | Access |
|---|
Need more practice in this area? Explore more questions →
Robinhood