Jump to content

Using RANK, or finding another way to do this


Recommended Posts

I get some results back from a query

Col 1    Col 2
X        ABC
X        DEF
X        GGH
Y        Blah
Z        Foo
X        Bar
Z        Something
G        Blah

 

I'd like to get the count of the item in Column 1, basically to associate each "instance" of the column 1 value to a 1-based index.

Col 1    Col 2      Col 3
X        ABC        1
X        DEF        2
X        GGH        3
Y        Blah      
Z        Foo        1
X        Bar        4
Z        Something  2
G        Foobar

 

In the case of Y and G, they only appear once in the result set, so I'd like column 3 to be either a 0 or NULL.

 

Ideas on the best way to do this?

Sorry but that doesn't make sense. There's no "changing" value; what I have shown here is a result set.

 

I've found a workaround: a subselect in the query that will show me the total rows. This is shown below. It will help me since I can just parse the results to determine 1,2,3,etc. for the row. Not really what I wanted, but it will do.

Col 1    Col 2      Col 3
X        ABC        4
X        DEF        4
X        GGH        4
Y        Blah       1
Z        Foo        2
X        Bar        4
Z        Something  2
G        Foobar     1

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.