Presumably, you want the ranking based on length
. This would be simpler in almost any other database, but in MS Access, you can use:
select t.*, o2.ranking
from (select o.*,
(select count(*)
from (select max(length) as max_length
from order as o2
group by o2.order
) as o2
where o2.max_length >= o.max_length
) as ranking
from (select order, max(length) as max_length
from t
group by order
) as o
) as o2 join
t
on o2.order = t.order;
Note: I can only hope that this handles ties in the maximum length the way you want them handled. Modifying that logic would be quite tricky.
By comparison, in any reasonable database you would use:
select t.*,
dense_rank() over (order by max_length desc) as ranking
from (select t.*,
max(length) over (partition by order) as max_length
from t
) t;
To me, this seems like a good reason to switch databases.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…