update: changed one time to show that the times per shipment may not be in sequential order always.
here is my input
create table test
(
shipment_id int,
stop_seq tinyint,
time datetime
)
insert into test values (1,1,'2009-8-10 8:00:00')
insert into test values (1,2,'2009-8-10 9:00:00')
insert into test values (1,3,'2009-8-10 10:00:00')
insert into test values (2,1,'2009-8-10 13:00:00')
insert into test values (2,2,'2009-8-10 14:00:00')
insert into test values (2,3,'2009-8-10 20:00:00')
insert into test values (2,4,'2009-8-10 18:00:00')
the output that i want is below
shipment_id start end
----------- ----- ---
1 8:00 10:00
2 13:00 18:00
i need to take the time from the min(stop)
row for each shipment and the time from the max(stop)
row and place in start/end respectively. i know this can be done with multiple queries rather easily but i am looking to see if a single select query can do this.
thanks!