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)
 Statistic

Author  Topic 

swansystem
Starting Member

2 Posts

Posted - 2011-01-13 : 10:05:36
I need found the most frequent value in a field. Who help me?

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2011-01-13 : 10:12:21
[code]
select field, count(*)
from table
group by field
[/code]
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2011-01-13 : 10:13:08
[code]SELECT TOP 1 fieldName FROM yourTable GROUP BY fieldName ORDER BY COUNT(fieldName) DESC;[/code]
Go to Top of Page

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2011-01-13 : 10:14:55
Damn, I forgot the order by..
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2011-01-13 : 10:18:25
I think you probably got the OP close enough
Go to Top of Page
   

- Advertisement -