Hi Dirk
Thanks for the link, it gave me some clues and i manged with trial and
error to get a result see SQL below. however 2 issues
this design wont work when querying a year field IE 2000 & 2001 i
would say it is the way i have the Max function working (there can
only be 1 max) right ?
Below is the table def
Table definition
Table = Daily-Stock-Prices
Fields
date Ck as date
Code Ck as string
High as double
Low as double
Close as double
Volume as long integer
SQL
SELECT [Daily-Stock-Prices].Code, Format([date],"mmm") AS [Month],
Max([Daily-Stock-Prices].Close) AS MaxOfClose
FROM [Daily-Stock-Prices]
GROUP BY Format([date],"yyyy"), [Daily-Stock-Prices].Code,
Format([date],"mm"), Format([date],"mmm")
HAVING ((([Daily-Stock-Prices].Code)="anz") AND
((Format([date],"mmm"))="jun"))
ORDER BY Format([date],"yyyy"), Format([date],"mm");
Any improvements or a faster method this queries about 230,000 rec so
far but only takes a couple of seconds i dont think that is 2 bad but
im sure there is way of speeding it up that where i need a bit of
help
I want to clarify something. When you list the fields
date Ck as date
Code Ck as string
are you saying that the fields named "date" and "Code" compose the
primary key of the table?
Your use of the names "date" and "Daily-Stock-Prices" cause a few
problems, because Access won't interpret them correctly unless they are
enclosed in brackets.
I'm no great SQL maven, but I think you are looking for a query along
these lines:
SELECT
P.Code,
Year(P.Date) AS CloseYear,
Month(P.Date) AS CloseMonth,
P.Close
FROM
[Daily-Stock-Prices] AS P
INNER JOIN
(SELECT
[Daily-Stock-Prices].Code,
Year([Date]) AS CloseYear,
Month([Date]) AS CloseMonth,
Max([Daily-Stock-Prices].Date) AS LastDate
FROM
[Daily-Stock-Prices]
GROUP BY
[Daily-Stock-Prices].Code,
Year([Date]),
Month([Date])
) AS D
ON (P.Date = D.LastDate) AND (P.Code = D.Code)
ORDER BY Year(P.Date), Month(P.Date);
You can apply whatever criteria you want to the result.
If this query works for you and you want to save it as a stored query,
be advised that when you save it, Access will insist on rewriting it in
its own idiosyncratic syntax with brackets instead of parentheses around
the subquery, which will make it hard to modify later because Access
will get confused between the subquery's brackets and the brackets
around the field and table names. If you were not using those
unfortunate names the problem wouldn't arise.