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 2000 Forums
 Transact-SQL (2000)
 Problem of count(*

Author  Topic 

acdacd
Yak Posting Veteran

63 Posts

Posted - 2005-08-15 : 03:59:33
select count(*), colA from tableA

Error
Column 'Jobs.JobID' is invalid in the select list because it is not contained in an aggregate function and there is no GROUP BY clause.

What is the problem?


be a hardworking people!!

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2005-08-15 : 04:33:49
Try this

Select Count(*),ColA From TableA
Group By ColA

Complicated things can be done by simple thinking
Go to Top of Page

mwjdavidson
Aged Yak Warrior

735 Posts

Posted - 2005-08-15 : 04:36:30
Hi
What resultset are you expecting? Count() is an aggregate function that returns a single value representing the count of all rows in a table including duplicates and nulls (when used with the '*').
colA must either be removed, added to a group by clause (to give the count for each value), or wrapped in an aggregate function.

Mark
Go to Top of Page

acdacd
Yak Posting Veteran

63 Posts

Posted - 2005-08-15 : 05:17:31
My orginal expected Result set.

Result
[Count ColA]
3 ab
3 cd
3 dy

I dont know what is aggreate fun before.If I want to get the result above. How to construct the query?

Also, "wrapped in an aggregate function". What does it mean?

Thx for all answers!



be a hardworking people!!
Go to Top of Page

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2005-08-15 : 05:23:53
hi
Did u tried this query .. i suppose this should work for you..

Select Count(*),ColA From TableA
Group By ColA

The Function llike Count,Sum,Avg etc are called as an aggregate Function..

this type of functions are used to generate the summary based query which i think you want.. that the count of the records in the colA are there...

you Can Search on Bol For Aggregate function.. this will give the better view.. of the Aggregate Fun :-)


Complicated things can be done by simple thinking
Go to Top of Page

acdacd
Yak Posting Veteran

63 Posts

Posted - 2005-08-15 : 05:56:51
I see.
Thank you very much

be a hardworking people!!
Go to Top of Page
   

- Advertisement -