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 |
|
Knarf180
Starting Member
42 Posts |
Posted - 2004-11-02 : 11:34:15
|
| Is it possible for SQL to figure out the frequency of a field value in a table?Lets say my records held the following in a given field:101410131311I would want the query to return the number plus the frequency it accurse.. IE:10 211 113 214 1I know this can be done with cursors and such, but I would end up running a heck of a lot of querys for something that could possibly have a simple answer. Figured I'd ask..Thanks a bunch - Frank |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2004-11-02 : 11:36:55
|
| cursors? Wow -- do people really write cursors for this stuff??this is SQL 101 stuff -- read up on SELECT statemetns and GROUP BY:select column, count(*)from tablegroup by column- Jeff |
 |
|
|
Knarf180
Starting Member
42 Posts |
Posted - 2004-11-02 : 11:49:45
|
| Geez, I've been drowning in such complicated Queries the passed few days that I'm losing touch with the basics. Thanks for clearing my head. |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2004-11-02 : 13:46:21
|
| hmmmcreate table #data (i int)insert #data select 10insert #data select 14insert #data select 10insert #data select 13insert #data select 13insert #data select 11create table #a (i int, cnt int)declare @i intdeclare x cursor for select * from #dataopen xfetch next from x into @iwhile @@FETCH_STATUS = 0begin update #a set cnt = cnt + 1 where i = @i if @@rowcount = 0 insert #a select @i, 1 fetch next from x into @iendclose xdeallocate xselect * from #adrop table #aI'm waiting for someone t odo a performance comparison :).==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
|
|
|