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
 SQL Server Development (2000)
 Selecting the category within a group with the largest total

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-07-25 : 08:51:20
Shawn writes "I have a feeling this is a simple question, but I just can't seem to get my head around it. I am using SQL Server 7.

I have data of the following form:


Poly Cat Area
---- --- ----
1 A 2
1 B 4
1 A 3
1 C 2
2 A 3
2 B 4
3 C 4


I would like to construct a query which sums up 'Cat's within each Poly and produce the Cat with the largest total area:


Poly Cat Area
---- --- ----
1 A 5
2 B 4
3 C 4


The biggest problem I have is with the Group By clause: I want to produce the Cat field which I do not want to Group By and which I can not use an aggregate function on.

Thanks."
   

- Advertisement -