SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 How to take the max but exclude a row?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

phrankbooth
Posting Yak Master

USA
157 Posts

Posted - 02/28/2014 :  23:57:58  Show Profile  Reply with Quote
In this table:
select * into #tmp
from
(
select 'abc' a, 'xyz' b, 10 c union all
select 'abc' a, 'ghi' b, 20 c union all
select 'abc' a, 'aaa' b, 30 c ) t

How can you group it by column a, b take max(c), BUT exclude rows with b='aaa'??

So that the result is 20.

Thanks


--PhB

khtan
In (Som, Ni, Yak)

Singapore
17601 Posts

Posted - 03/01/2014 :  00:05:10  Show Profile  Reply with Quote

select  max(c)
from    #tmp
where   b <> 'aaa'



KH
Time is always against us

Go to Top of Page

phrankbooth
Posting Yak Master

USA
157 Posts

Posted - 03/01/2014 :  00:21:12  Show Profile  Reply with Quote
thanks for your reply.

sorry, I should have been clearer.

I simplified the table, but I talked about grouping it because 'aaa' is not the only field value, there will be more rows with other groupings besides 'abc'

--PhB
Go to Top of Page

khtan
In (Som, Ni, Yak)

Singapore
17601 Posts

Posted - 03/01/2014 :  00:31:22  Show Profile  Reply with Quote
then can you illustrate further on your requirement ?


KH
Time is always against us

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000