I think that if you change the less than to greater Than in the subquery you
will get the ranking you desire.
Adding another weatherstation would mean you would need to add that to the
WHERE clause of the subquery. Assuming the field for identifying the weather
station was WXID, your subquery would look like the following:
(SELECT COUNT(*) FROM
[Test_1] Q1
WHERE Year(Q1.[dt]) = Year(Q.[dt])
AND Q1.[Avg] +(Q1.[dt]/100000) > Q.[Avg]+(Q.[dt]/100000)
AND Q1.WXID + Q.WXID)+1 AS Rank
John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
that is better but i still need the rank descending. By descending i mean
the highest temperature has a rank of 1 then the ties are solved by the
chronologically first getting a higher rank (which is actually a lower
number). also what would i need to do to add an extra group of weather
station.
KARL DEWEY said:
Try this ---
SELECT Year(Q.[dt]) AS CY_Year, Q.dt, Q.Avg, (SELECT COUNT(*) FROM
[Test_1] Q1
WHERE Year(Q1.[dt]) = Year(Q.[dt])
AND Q1.[Avg] +(Q1.[dt]/100000) < Q.[Avg]+(Q.[dt]/100000))+1 AS Rank
FROM Test_1 AS Q
ORDER BY Year(Q.[dt]), Q.[Avg]+(Q.[dt]/100000);
--
KARL DEWEY
Build a little - Test a little
:
The tie breaker for ties would be the date, so which ever tie temperature
happened first chronologically would get a higher rank.
:
That produces some results but it does not account for ties in the data, also
i would prefer to rank descending.
:
Try this --
SELECT Year(Q.[dt]) AS CY_Year, Q.dt, Q.Avg, (SELECT COUNT(*) FROM [Test] Q1
WHERE Year(Q1.[dt]) = Year(Q.[dt])
AND Q1.[Avg] < Q.[Avg])+1 AS Rank
FROM Test AS Q
ORDER BY Year(Q.[dt]), Q.Avg DESC;
--
KARL DEWEY
Build a little - Test a little
:
I am trying to create a query that effectively ranks temperature from highest
to lowest by year. I need a rank assigned by year 1-365 (366 for leap
years). I have a table with the actual data and i can easily sort the data
correclty but I need to have a field with the rank by year. below is how far
i have gotten.
SELECT Year([dt]) AS [year], test.avg, test.Dt
FROM test
ORDER BY Year([dt]), test.avg DESC , test.Dt;