INTRODUCTION TO THE DATABASE TABLE -
I am working on a table on the stock market prices database. My table has data for the following fields -
ID
SYMBOL
OPEN
TALL
Low
Close
VOLUME
VOLUME CHANGE
VOLUME CHANGE%
OPEN_INT
SECTOR
TIMESTAMP
New data is added daily to the table from Monday to Friday, based on changes in stock market prices for that day. The current requirement is based on the VOLUME field, which shows the volume traded for a particular stock on a daily basis.
REQUIREMENT - To get the average and total volume for the last 10.15 and 30 days, respectively.
METHOD USED DURING - I created these 9 SEPARATE QUESTIONS to get the desired results - First I created these 3 queries to derive the last last 10.15 and 30 dates from the current table:
qryLast10DaysStored
qryLast15DaysStored
qryLast30DaysStored
Then I created these 3 queries to get the corresponding MEANS:
qrySymbolAvgVolume10Days
qrySymbolAvgVolume15Days
qrySymbolAvgVolume30Days
And then I created these 3 queries to get the corresponding TOTALS:
qrySymbolTotalVolume10Days
qrySymbolTotalVolume15Days
qrySymbolTotalVolume30Days
PROBLEM RELATED TO THE CURRENT METHOD - Now my problem is that I had so many different queries, while I wanted to get the output in One Single Query , as shown in "Excel Sheet Shot":
http://i49.tinypic.com/256tgcp.png
NECESSARY DECISIONS - Is there a way by which I can get these required fields in ONE SINGLE TIME, so that I do not need to look for several places for the required fields? Can someone please tell me how to get all these separate requests in one -
A) Either selecting or moving the results from these individual individual queries to one.
B) Or by creating a new query that calculates all of these fields within itself, so that these individual individual queries are no longer needed. That would be the best solution, I think.
One Date Clarification - Some friend might think why I used the Top 10.15 and 30 method to get the last 10.15 and 30 date values. Why didn’t I use the PC date to get these values? Or used something like -
("VOLUME","tbl-B", "TimeStamp BETWEEN Date() - 10 AND Date()")
The answer is that I need my request to “Read” the date from the “TIMESTAMP” field, and then perform its calculations, respectively, for LAST / MOST RECENT “10 days, 15 days, 30 days” FOR WHICH DATA IS AVAILABLE IN THE TABLE, WITHOUT SECURITY WHAT IS THIS DATE. It should not depend on the current date.
If there is a better way or more efficient way to create these queries, please enlighten.