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.
| 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 countsome value 24another word 20a value 5 (and so on...)How can I do this?- - - -- Will -- - - -http://www.strohlsitedesign.comhttp://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 yourtablegroup by nvarcharcolMadhivananFailing to plan is Planning to fail |
 |
|
|
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.comhttp://blog.strohlsitedesign.com/http://skins.strohlsitedesign.com/ |
 |
|
|
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(*) descEm |
 |
|
|
|
|
|