We help IT Professionals succeed at work.
Get Started

SQL UPDATE statement to apply consecutive numbering on a per-customer basis

sealeopard asked
Last Modified: 2010-05-18
We have a table containing customer info as follows:

Customer_ID | Token | Data | Order_No
123456         |1234    | xxx   |
123456         |1236    | xxx   |
123456         |1234    | xxx   |
123457         |1236    | xxx   |
123457         |1436    | xxx   |

Order_No is currently not used, however, we would like to assign order number on a per customer-basis. The "Token" field is a unique BIGINT number and the Customer_ID is an INT, the Customer ID can show up in multiple rows, however will always have an unique token. Below is the table with the order numbers that we'd like to get at

Customer_ID | Token | Data | Order_No
123456         |1234    | xxx   |   1
123456         |1236    | xxx   |   2
123456         |1244    | xxx   |   3
123457         |1236    | xxx   |   1
123457         |1436    | xxx   |   2

So far, we haven't come up a solution that uses a single SQL statement.
Watch Question
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE