Thread: Adding orders

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    1
    Rep Power
    0

    Adding orders


    Hi I am newbiew to SQL and please accept my fundamental question.

    What I have been struggling to get at is to add click orders under the following situation:

    UserID Click Purchase
    0001 1 0
    0001 2 1
    0001 3 0
    0001 4 0
    0001 5 1
    0002 1 0
    0002 2 1
    0002 3 0

    I would like to add a column showing orders based on purchase like:

    UserID Click Purchase Order
    0001 1 0 1
    0001 2 1 1
    0001 3 0 2
    0001 4 0 2
    0001 5 1 2
    0002 1 0 1
    0002 2 1 1
    0002 3 0 2

    So this order gets refreshed when a different userID shows up and order gets incremental once purchase has been made. I thought I will use dense_rank() over (partition UserID), but this increment in order needs to refer to purchase which is the one above it.

    Could you please help me out to come up with SQL commands to cope wit this? I currently programmed it in Python which is slow for a large # of records.

    Thanks in advance!
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    158
    Rep Power
    10
    I don't understand what you want to do, can you post an example of the kind of changes that happen and the result that you want?

IMN logo majestic logo threadwatch logo seochat tools logo