Re: Counting times each element appears



Need to leave out the 'distinct' else you get '1' as a count() for all records in the result set.

==================================
1> select foo,
2>        count(distinct foo)
3> from   foobar
4> group by foo
5> go

 foo
 ----------- -----------
           1           1
           2           1
           3           1
           4           1

(4 rows affected)
==================================
1> select foo,
2>        count(foo)
3> from   foobar
4> group by foo
5> go

 foo
 ----------- -----------
           1           6
           2           5
           3           4
           4           3

(4 rows affected)
==================================



--CELKO-- wrote:
SELECT Foo, COUNT (DISTINCT foo )
   FROM Foobar
 GROUP BY Foo;

.