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)
 Using two aggregate Functions together

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-08-26 : 11:22:17
Krishna writes "I Have a table like the following structure and data in it.
I want maximum Qty Purchased ItemCodes(i.e,10 and 12 in the given example).
this shud be in a single query with out using TOP clause


ItemCode DateofPurchase QtyPurchased
----------- ----------- -------------------
10 2002-01-02 100
10 2002-01-04 200
11 2002-01-03 19
11 2002-01-03 19
12 2002-01-06 50
12 2002-02-06 250



Thanks,
Krishna."

nr
SQLTeam MVY

12543 Posts

Posted - 2002-08-26 : 12:26:42
something like

select ItemCode
from tbl
group by ItemCode
having sum(QtyPurchased) =
(select max(QtyPurchased)
from (select QtyPurchased = sum(QtyPurchased)
from tbl group by ItemCode) as a)


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -