I tried this and I got a case where it doesn't work correctly and I listed it
below:
SELECT T.customerID, T.PurchaseDate, (SELECT COUNT(*)
FROM [Cameron] T1
WHERE T1.customerID = T.customerID AND T1.PurchaseDate & T1.PrimaryKey
<=
T.PurchaseDate & T.PrimaryKey) AS Rank
FROM Cameron AS T
ORDER BY T.customerID, T.PurchaseDate;
customerID PurchaseDate PrimaryKey Rank
1200 12/2/2003 15448 2
1200 8/13/2007 41311 3
1200 11/10/2007 44031 1
I am temporarily doing this in excel and importing the correct rank. In
excel it is so simple, sort and use a countif formula.
Cameron
KARL DEWEY said:
If you have a primary key field like an autonumber that try this --
SELECT customerID, PurchaseDate, (SELECT COUNT(*)
FROM [Cameron] T1
WHERE T1.customerID = T.customerID AND T1.PurchaseDate & [PrimaryKey]
<= T.PurchaseDate & [PrimaryKey]) AS Rank
FROM [Cameron] AS T
ORDER BY customerID, PurchaseDate;
--
KARL DEWEY
Build a little - Test a little
:
Use a totals query ahead of this.
--
KARL DEWEY
Build a little - Test a little
:
The problem I am having with this query is if the customer purchases more
than once on the same day, which means it doesn't count up for the second
purchase. Any idea's how to correct that? I don't even care if they are in
any type of order for the same date purchases, just that they are counted up.
:
Try this --
SELECT customerID, PurchaseDate, (SELECT COUNT(*)
FROM [Cameron] T1
WHERE T1.customerID = T.customerID AND T1.PurchaseDate <=
T.PurchaseDate) AS Rank
FROM [Cameron] AS T
ORDER BY customerID, PurchaseDate;
--
KARL DEWEY
Build a little - Test a little
:
I need to group an alphanumeric customerID and Order by PurchaseDate, then
assign each ascending purchase its PurchaseRank. Please Help.
customerID PurchaseDate PurchaseRank (new field needed)
EA454 1/1/08 1
EA454 3/1/08 2
GV152 9/1/07 1