You can create a query that numbers/ranks records within groups. For instance the Orders table in Northwind has fields:
[tt][color #204A87]
OrderID unique autonumber
CustomerID
OrderDate[/color]
[/tt]
Assuming you want to display the records by customer with each record numbered from 1 to whatever based on the OrderDate. Each different customer would begin numbering back at 1.
The SQL view is:
[code SQL]SELECT Orders.OrderID, Orders.CustomerID, Orders.OrderDate, Count(Orders_1.OrderID) AS Rank
FROM Orders AS Orders_1 INNER JOIN Orders ON Orders_1.CustomerID = Orders.CustomerID
WHERE Orders.OrderDate>=[Orders_1].[OrderDate]
GROUP BY Orders.OrderID, Orders.CustomerID, Orders.OrderDate
ORDER BY Orders.CustomerID, Orders.OrderDate;[/code]
If you don't want to group by CustomerID, just delete the join line between the two tables:
The new SQL view is:
[code SQL]SELECT Orders.OrderID, Orders.OrderDate, Orders.CustomerID, Count(Orders_1.OrderID) AS Rank
FROM Orders AS Orders_1, Orders
WHERE Orders.OrderDate>[Orders_1].[OrderDate]
GROUP BY Orders.OrderID, Orders.OrderDate, Orders.CustomerID
ORDER BY Orders.OrderDate, Orders.CustomerID;[/code]
Orders on the same date will have the same rank value.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.