最簡單的解決辦法是這樣的:
select
Field1_min, (select max(TimeStamp) from table1 where Field1 = Field1_min) as ts1min,
Field1_max, (select max(TimeStamp) from table1 where Field1 = Field1_max) as ts1max,
Field2_min, (select max(TimeStamp) from table1 where Field2 = Field2_min) as ts2min,
Field2_max, (select max(TimeStamp) from table1 where Field2 = Field2_max) as ts2max,
Field3_min, (select max(TimeStamp) from table1 where Field3 = Field3_min) as ts3min,
Field3_max, (select max(TimeStamp) from table1 where Field3 = Field3_max) as ts3max,
Field4_min, (select max(TimeStamp) from table1 where Field4 = Field4_min) as ts4min,
Field4_max, (select max(TimeStamp) from table1 where Field4 = Field4_max) as ts4max
from (
select
min(Field1) as Field1_min, max(Field1) as Field1_max,
min(Field2) as Field2_min, max(Field2) as Field2_max,
min(Field3) as Field3_min, max(Field3) as Field3_max,
min(Field4) as Field4_min, max(Field4) as Field4_max
from table1
) S
哪個版本的SQLServer的是什麼? –