B
bgetson
I've got a table with fields: ND, M, S, T, and P. The primary key is
comprised of those first four fields.
I have a query which is supposed to calculate a record's P (profit) as
a percentage of the maximum of all records with the most recent ND
(date). My problem is that everything I do seems to be implicitly
grouped by M.
When I want to find the maximum of all records with the most recent
ND, it's finding the maximum of all records with a particular M and
the most recent ND. When I want to display all records with the most
recent ND (by selecting TOP 1 and sort descending), it again limits to
all records with a particular M.
SELECT TOP 1 tblData.M, tblData.S, tblData.T, tblData.P/(SELECT Max(P)
FROM tblData AS X WHERE X.ND=tblData.ND)
FROM tblData
ORDER BY tblData.ND DESC;
It's my first day with SQL, and I can't figure out what it is, or even
a workaround for it.
Any help would be greatly appreciated.
-bgetson
comprised of those first four fields.
I have a query which is supposed to calculate a record's P (profit) as
a percentage of the maximum of all records with the most recent ND
(date). My problem is that everything I do seems to be implicitly
grouped by M.
When I want to find the maximum of all records with the most recent
ND, it's finding the maximum of all records with a particular M and
the most recent ND. When I want to display all records with the most
recent ND (by selecting TOP 1 and sort descending), it again limits to
all records with a particular M.
SELECT TOP 1 tblData.M, tblData.S, tblData.T, tblData.P/(SELECT Max(P)
FROM tblData AS X WHERE X.ND=tblData.ND)
FROM tblData
ORDER BY tblData.ND DESC;
It's my first day with SQL, and I can't figure out what it is, or even
a workaround for it.
Any help would be greatly appreciated.
-bgetson