Query help

  • Hi

    I have a requirement where col 3 should contain values as in sample below (col1 and col2 are already populated)

    Col1 col2 col3

    abc 1 1

    abc 2 1

    abc 3 1

    fgh 1 2

    dft 1 3

    fgh 2 2

    abc 4 1

    Can someone pls help

    I know I can use update statement and group by clause but it will take time for millions of records .. hence i'm looking for some function like rank(), dense rank() but somehow not able to do it

  • Would you mind showing us what you've done so far and where you got stuck?



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

  • Hi,

    Do you want a query output in the above format or you want to populate your table(3rd column) ?

    I created a table ABC with 2 columns .

    col1 col2

    abc1

    abc2

    abc3

    fgh1

    dft1

    fgh2

    abc4

    Executed the following query:

    select col1,col2,dense_rank() over (order by col1) as 'col3' from dbo.ABC

    it gave me :

    col1 col2 col3

    abc11

    abc21

    abc31

    abc41

    dft12

    fgh23

    fgh13

    is this what u want ?

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

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