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 2008 Forums
 Transact-SQL (2008)
 Return one aggregate row from group by

Author  Topic 

phrankbooth
Posting Yak Master

162 Posts

Posted - 2011-11-01 : 13:34:15
In the table below, I'd like to group by subtype, sum up the dr values and take AZ as the title.

subtype dr title
ATOZ 100.00 AZ
ATOZ 200.00 AZ - EU
ATOZ 300.00 AZ - UK

this is what my result should be: ATOZ, 600.00, AZ

It's the getting just AZ to one row that I'm having trouble with.

Thanks!

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-11-01 : 13:40:22
SELECT SubType, SUM(DR) AS DR, MIN(Title) AS Title
FROM myTable
GROUP BY SubType
Go to Top of Page

phrankbooth
Posting Yak Master

162 Posts

Posted - 2011-11-01 : 13:48:29
Perfect, thank you! You're beautiful :)

--PhB
Go to Top of Page
   

- Advertisement -