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)
 How to display the maximum / largest of count()?

Author  Topic 

cshong
Starting Member

8 Posts

Posted - 2008-10-10 : 11:19:06
I'm using Microsoft SQL 2005 Express Edition. I'm a student and I'm new to database.

I want to use SELECT statement to display the maximum or largest number of count(columnname). I tried to use max(count(columnname)) but it is not supported and the SQL software return an error message.

So, how to use SELECT statement to display the maximum or largest number of count(columnname)? This is required in doing the questions in my assignment.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-10 : 11:38:41
SELECT max(colcount)
FROM
(
SELECT COUNT(Col) AS colcount,...
FROM..
GROUP BY...
)t
Go to Top of Page

andros30
Yak Posting Veteran

80 Posts

Posted - 2008-10-10 : 14:43:34
Visakh, can this be applied to getting the max date as well? For example, if my table has 10/1/08...10/10/08 and I want to get 10/10/08:

SELECT max(LatestAgeDate)
FROM
(SELECT max(AgeDate) as LatestAgeDate
FROM...)t
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-11 : 01:16:08
quote:
Originally posted by andros30

Visakh, can this be applied to getting the max date as well? For example, if my table has 10/1/08...10/10/08 and I want to get 10/10/08:

SELECT max(LatestAgeDate)
FROM
(SELECT max(AgeDate) as LatestAgeDate
FROM...)t


yup. but the accuracy of result depends on datatype of AgeDate field. If its datetime it will return you maximum date value. if varchar then it will sort it as a string and return max value among them.
Go to Top of Page
   

- Advertisement -