JapanFreak
Registered User.
- Local time
- Today, 09:32
- Joined
- Aug 25, 2007
- Messages
- 45
Hi there,
I have one table, called tblTransactions, which contains records on security market transactions. For each buy and sell order, respectively it contains one dataset with columns Date, Ticker (i.e. the unique identifier of each security), Quantity (positive for buy, negative for sell orders) and Price (at which the trade was executed).
The following SQL query code gives me then the composition of my security portfolio as per any arbitrarily chosen date (here 1/10/2007):
For instance, for some trades like the following...
Data --- Ticker --- Quantity --- Price
01/01/07 --- AAA --- 50 --- $50
01/01/07 --- BBB --- 25 --- $75
01/15/07 --- AAA --- 30 --- $60
...it results in the following query results:
01/10/07:
Ticker --- TotalQuantity
AAA --- 50
BBB --- 25
01/20/07:
Ticker --- TotalQuantity
AAA --- 80
BBB --- 25
However, I would like to add a column to this query, which gives me the number of trades for each particular stock. For instance, the query result based on the sample data above should look like follows as per 01/20/07:
Ticker --- TotalQuantity --- NumberOfTrades
AAA --- 80 --- 2
BBB --- 25 --- 1
I have absolutely no idea how to achieve that. I would be very happy for any suggestions.
Best regards,
JapanFreak
I have one table, called tblTransactions, which contains records on security market transactions. For each buy and sell order, respectively it contains one dataset with columns Date, Ticker (i.e. the unique identifier of each security), Quantity (positive for buy, negative for sell orders) and Price (at which the trade was executed).
The following SQL query code gives me then the composition of my security portfolio as per any arbitrarily chosen date (here 1/10/2007):
Code:
SELECT [tblTransactions].[Ticker], sum([tblTransactions].[Quantity]) AS TotalQuantity
FROM tblTransactions
WHERE [tblTransactions].[Date]<=#1/10/2007#
GROUP BY [tblTransactions].[Ticker]
HAVING sum(tblTransactions.Quantity) >0
ORDER BY [tblTransactions].[Ticker];
For instance, for some trades like the following...
Data --- Ticker --- Quantity --- Price
01/01/07 --- AAA --- 50 --- $50
01/01/07 --- BBB --- 25 --- $75
01/15/07 --- AAA --- 30 --- $60
...it results in the following query results:
01/10/07:
Ticker --- TotalQuantity
AAA --- 50
BBB --- 25
01/20/07:
Ticker --- TotalQuantity
AAA --- 80
BBB --- 25
However, I would like to add a column to this query, which gives me the number of trades for each particular stock. For instance, the query result based on the sample data above should look like follows as per 01/20/07:
Ticker --- TotalQuantity --- NumberOfTrades
AAA --- 80 --- 2
BBB --- 25 --- 1
I have absolutely no idea how to achieve that. I would be very happy for any suggestions.
Best regards,
JapanFreak