November 20, 2006 at 11:07 pm
My data, in SQL 2000
A 2000
A 3000
A 1000
A 1500
B 1000
C 5000
C 1000
How do I do this below,for A the max of the values is 3000, B is 1000 and C is 5000
A 3000 3000
A 2000 3000
A 1500 3000
A 1000 3000
B 1000 1000
C 3000 5000
C 1000 5000
November 21, 2006 at 12:22 am
Hi Digs
consider the following table:
create table #test(id char(1),value int)
insert #test
select 'A', 2000
union all
SELECT 'A',3000
union all
SELECT 'A',1000
union all
SELECT 'A',1500
union all
SELECT 'B',1000
union all
SELECT 'C',5000
union all
SELECT 'C',1000
I think this is what you need:
select id,max(value)
from #test
group by id
but if the desire result is exactly as what you have shown,do the following snippet :
select T.*,A.maxval
from
#test T
inner join
(select id,max(value)
from #test
group by id) A(id,maxval)
on A.id=T.id
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy