Dear All,
I am not the SQL expert and I would be very happy if someone could help me with the following question:
The first query gives me the closing price of the last trading day (here just 11/28/08):
The second query tells me, what the highest closing price in the last 20 trading days (excluding the last one, 11/28/08) was:
Both of them work so far. Now I have two questions:
1) I want to combine them into one query which gives me the maximum of both results for each Ticker and the corresponding Date. I guess I have to work with Joins but honestly I have no idea...
2) I want that the end result shows only those, where the price of the last trading day (i.e, here 11/28/08) is greater than the highest of the last 20 trading days. I guess the result of question 1 then needs some "Having" clause?
I would be very happy if somebody could give me some hint here...
Thank you very much.
Diana
(Data has 6 columns: Ticker, dDate, Open, High, Low, Close and contains price data for stocks)
I am not the SQL expert and I would be very happy if someone could help me with the following question:
The first query gives me the closing price of the last trading day (here just 11/28/08):
Code:
SELECT Ticker, Close
FROM Data
WHERE dDate=#11/28/2008#
GROUP BY Ticker, dDate, Close
The second query tells me, what the highest closing price in the last 20 trading days (excluding the last one, 11/28/08) was:
Code:
SELECT Ticker, MAX(Close)
FROM
(SELECT TOP 20 Ticker, Close
FROM Data
WHERE dDate<#11/28/2008#
GROUP BY Ticker, dDate, Close
ORDER BY dDate DESC)
GROUP BY Ticker, dDate
Both of them work so far. Now I have two questions:
1) I want to combine them into one query which gives me the maximum of both results for each Ticker and the corresponding Date. I guess I have to work with Joins but honestly I have no idea...
2) I want that the end result shows only those, where the price of the last trading day (i.e, here 11/28/08) is greater than the highest of the last 20 trading days. I guess the result of question 1 then needs some "Having" clause?
I would be very happy if somebody could give me some hint here...
Thank you very much.
Diana
(Data has 6 columns: Ticker, dDate, Open, High, Low, Close and contains price data for stocks)
Last edited: