JapanFreak
Registered User.
- Local time
- Today, 20:04
- Joined
- Aug 25, 2007
- Messages
- 45
Hi there,
I have a problem with an SQL query related to a table which contains stock market transactions. The query requests data from a table called tblTransactions with (among others) columns Date, Ticker, Quantity and Price.
By adding up the quantities bought (positive number) and sold (negative number) I can determine the number of stocks I hold at a certain date for each ticker.
What I am looking for is the date, when a position in a certain stock identified by a ticker (I use the example of GT) is sold completely, i.e. the quantity is zero again.
The following code is my draft, but unfortunately it does not work because Access obviously does not allow to use an aggregate function like sum(Quantity) in the WHERE part of a sub-query.
How do I have to deal with problems like this? I am happy for any hint that could lead to a solution...
Thank you very much.
Best regards,
JapanFreak
I have a problem with an SQL query related to a table which contains stock market transactions. The query requests data from a table called tblTransactions with (among others) columns Date, Ticker, Quantity and Price.
By adding up the quantities bought (positive number) and sold (negative number) I can determine the number of stocks I hold at a certain date for each ticker.
What I am looking for is the date, when a position in a certain stock identified by a ticker (I use the example of GT) is sold completely, i.e. the quantity is zero again.
The following code is my draft, but unfortunately it does not work because Access obviously does not allow to use an aggregate function like sum(Quantity) in the WHERE part of a sub-query.
Code:
SELECT T.Ticker, (SELECT Top 1 [Date] FROM [tblTransactions] WHERE sum(T.Quantity)=0 ORDER BY [Date] DESC) AS SellDate
FROM tblTransactions AS T
WHERE T.Ticker="GT"
GROUP BY T.Ticker;
How do I have to deal with problems like this? I am happy for any hint that could lead to a solution...
Thank you very much.
Best regards,
JapanFreak