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)
 Getting max value of a column (group by)

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-04-03 : 16:26:48
Darren writes "Hi folks,

We have a table something like the following:

NUM CODE AMOUNT
1 A 10
1 B 20
1 C 15
2 D 20
2 B 10

What we want to end up with is the following:

NUM CODE AMOUNT
1 B 45
2 D 30


i.e. the sum of the AMOUNT for each NUM, together with the CODE which had the largest AMOUNT in the original.

Note that this has to be done using standard SQL - temp tables, stored procs are not allowed (although we can use views).

Thanks."
   

- Advertisement -