Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Need to count and rank NVARCHAR Column

Author  Topic 

hismightiness
Posting Yak Master

164 Posts

Posted - 2008-04-02 : 23:09:19
Assuming that I have a table similar to this simplified version:

CREATE TABLE [SomeTable] ([Field1] NVARCHAR(50));


How could I count and rank the instances of specific values in the "field1" column? For example, let's say that I want to show the frequency of the column values like so:

field1        count
some value 24
another word 20
a value 5


(and so on...)

How can I do this?

- - - -
- Will -
- - - -
http://www.strohlsitedesign.com
http://blog.strohlsitedesign.com/
http://skins.strohlsitedesign.com/

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-04-03 : 02:47:55
Did you try this?

Select nvarcharcol,count(*) from yourtable
group by nvarcharcol

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

hismightiness
Posting Yak Master

164 Posts

Posted - 2008-04-03 : 08:50:14
I did not realize that that would provide the correct counts. It looks to be correct though. Thanks!

- - - -
- Will -
- - - -
http://www.strohlsitedesign.com
http://blog.strohlsitedesign.com/
http://skins.strohlsitedesign.com/
Go to Top of Page

elancaster
A very urgent SQL Yakette

1208 Posts

Posted - 2008-04-03 : 08:55:33
and to 'rank' it as you described...

order by count(*) desc

Em
Go to Top of Page
   

- Advertisement -