-
Adding count to multiple columns
I have a database that sort of is put together like this:
There is one column with a unique identifier, another column that groups the unique identifier and then I am trying to add a 3rd column that is a count of how many unique identifiers there are for a specific group
This is what I have:
A 1 ?
A 2 ?
B 3 ?
B 4 ?
B 5 ?
C 6 ?
This is what I want
A 1 1
A 2 2
B 3 1
B 4 2
B 5 3
C 6 1
Can anybody help to identify a query to do this?
Thanks! (I'm new to SQL)
-
I would play with my code using the DISTINCT SQL command, then look at my middleware to output a recordcount. Here s a good cheat sheet for SQL commands...
http://www.pinaldave.com/sql-downloa...CheatSheet.pdf
also: Here is a resource Microsoft has made avaialble for web trainings for developers...
http://www.msdev.com/
just type in SQL server in the search box, or any other MS technology you are interested in earning and a series of web trainings will come up for you to utilize.
Hope this helps!
Larry D
MSAE
-
select first_column,second_column,(row_number() over (partition by first_column,second_column order by first_column,second_column) as third_column from table
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|