b. Write a SELECT statement that returns Ticker, its average closing price, its maximal closing price, and its minimal closing price in the month of September 2019. Make sure that your data is well formatted and all columns have names.
These are the fields(database is cut short)
Date | Ticker | Open | High | Low | Close | Volume | textdate |
3/18/19 | IBM | 139.83 | 140.37 | 138.72 | 140.21 | 3268500 | 03/18/2019 |
3/19/19 | IBM | 140.96 | 141.7 | 140 | 140.49 | 3482300 | 03/19/2019 |
3/20/19 | IBM | 140.53 | 140.7 | 138.98 | 139.6 | 3649500 | 03/20/2019 |
3/21/19 | IBM | 139.1 | 142.12 | 138.88 | 141.44 | 3605400 | 03/21/2019 |
3/22/19 | IBM | 140.97 | 141.44 | 138.9 | 139.45 | 3877200 | 03/22/2019 |
3/25/19 | IBM | 139.06 | 139.91 | 138.35 | 139.18 | 2839800 | 03/25/2019 |
3/26/19 | IBM | 139.93 | 141.02 | 139.42 | 140.22 | 2553700 | 03/26/2019 |
3/27/19 | IBM | 140.41 | 140.49 | 138.4 | 139.24 | 3098200 | 03/27/2019 |
3/28/19 | IBM | 139.91 | 140.44 | 139.1 | 139.92 | 2663900 | 03/28/2019 |
3/29/19 | IBM | 140.5 | 141.22 | 140.15 | 141.1 | 3101400 | 03/29/2019 |
4/1/19 | IBM | 141.51 | 143.41 | 141.51 | 143.3 | 3984300 | 04/01/2019 |
4/2/19 | IBM | 143.35 | 143.95 | 142.6 | 143 | 2404800 | 04/02/2019 |
4/3/19 | IBM | 143.65 | 144.22 | 143.01 | 143.63 | 2681200 | 04/03/2019 |
4/4/19 | IBM | 143.62 | 144.14 | 142.54 | 142.78 | 2771100 | 04/04/2019 |
4/5/19 | IBM | 143.29 | 143.5 | 142.46 | 143.28 | 2731800 | 04/05/2019 |
4/8/19 | IBM | 143.02 | 143.42 | 142.87 | 143.39 | 2118200 | 04/08/2019 |
Solution)
SELECT Ticker, AVG(Close) as AvgClosingPrice, MAX(Close)
as MaxClosingPrince, MIN(Close) as MinClosingPrice from
tableName
WHERE Date>='01/09/2019' AND Date<'01/10/2019''
GROUP BY Ticker;
Explanation: Please replace the tableName by the actual name of the table, aggregate functions AVG(),MAX() and MIN() are used with the where clause and group by ticker is used.The date is selected as greater than or equal to 1 september and less than 1 october 2019.
NOTE:Please upvote if you liked my answer and comment if you need any modification or explanation
Get Answers For Free
Most questions answered within 1 hours.