Please suggest the query

  • Hear is what I have

    I have this data

    I wanted to calculate the total number for day before the first change ie A to B and Total number of days on the last change from B to A

    Sample Data

    ID Type Days

    101 A 2

    101 B 3

    103 A 4

    103 A 2

    103 B 1

    103 A 5

    103 B 4

    103 A 4

    104 A 5

    104 A 2

    104 B 1

    104 A 5

    104 B 4

    Sample output data

    ID Total days before (A to B) Total day before the (B to A)

    the first type change last type change

    101 2 0

    103 6 4

    104 7 9

  • Your post has gone 2 days with no responses. Take a look at the first link in my signature line below to increase the odds of your question being answered. 😉

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply