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)
 Using MIN/MAX with Count(). Please help me.

Author  Topic 

txk2601
Starting Member

19 Posts

Posted - 2009-03-07 : 10:52:41
Hi all.

I have got problem with Max/Min and Count functions by following:

SELECT BookTypeID, MIN(Count(BookID)) From tblBookInfo GROUP By BookTypeID

I receive a message "Cannot perform an aggregate function on an expression containing an aggregate or a subquery." Please help me. Thanks a lot

lionofdezert
Aged Yak Warrior

885 Posts

Posted - 2009-03-07 : 12:40:49
use sub query to count first
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-03-07 : 13:24:34
[code]
SELECT MIN(BookCount)
FROM
(
SELECT BookTypeID, Count(BookID) AS BookCount From tblBookInfo GROUP By BookTypeID
)t
[/code]
Go to Top of Page

txk2601
Starting Member

19 Posts

Posted - 2009-03-09 : 21:49:05
Thanks visakh16 and Lionofdezert very much!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-03-10 : 03:08:09
welcome
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-03-10 : 04:51:54
or

SELECT top 1 BookTypeID, Count(BookID) From tblBookInfo GROUP By BookTypeID
order by Count(BookID) asc


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -