RE: Distinct Max Value?
From: Alejandro Mesa (AlejandroMesa_at_discussions.microsoft.com)
Date: 01/17/05
- Next message: Bob Barrows [MVP]: "Re: Can a cursor return rows from a stored procedure?"
- Previous message: Bob Barrows [MVP]: "Re: Distinct Max Value?"
- In reply to: rjcmbc: "Distinct Max Value?"
- Next in thread: David Gugick: "Re: Distinct Max Value?"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 17 Jan 2005 11:37:03 -0800
Try:
declare @t table (run_id int not null, SignOffTime datetime)
insert into @t values(001, '2005-01-17T20:00:00')
insert into @t values(001, '2005-01-17T21:00:00')
insert into @t values(001, '2005-01-17T22:00:00')
select
a.run_id,
a.SignOffTime,
b.MAXSignOffTime
from
@t as a
inner join
(select run_id, max(SignOffTime) from @t group by run_id) as b(run_id,
MAXSignOffTime)
on a.run_id = b.run_id
order by
1
go
AMB
"rjcmbc" wrote:
> We have numerous instances of the same Runnumber (eg. Runnumber = 001) that
> with different SignOffTimes (eg, 8pm, 9pm, 10pm etc).
>
> I am trying to isolate the MAX SignOffTime for each Runnumber group (in this
> example - 001 = 10pm) as well as populating an additional field in a view
> called 'MaxSignOffTime' for that Runnumber group. Ultimately my view would
> show the following:
>
> Run# SignOffTime MAXSignOffTime
> 001 8pm 10pm
> 001 9pm 10pm
> 001 10pm 10pm
>
> Anyhelp is appreciated!
>
> rjcmbc
- Next message: Bob Barrows [MVP]: "Re: Can a cursor return rows from a stored procedure?"
- Previous message: Bob Barrows [MVP]: "Re: Distinct Max Value?"
- In reply to: rjcmbc: "Distinct Max Value?"
- Next in thread: David Gugick: "Re: Distinct Max Value?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|