Guest User

Untitled

a guest
May 2nd, 2018
86
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. declare @TestData Table
  2. (
  3.    [Time]           int
  4.   ,[Temp_Front]     int
  5.   ,[Temp_Center]    int
  6.   ,[Temp_Back]      int
  7. );
  8.  
  9. insert into @TestData
  10. values
  11.     (2, 26, 27, 27),
  12.     (3, 26, 28, 27),
  13.     (4, 27, 28, 27),
  14.     (5, 27, 28, 28);
  15.  
  16.  
  17.  
  18.  
  19. ;with [min] as (
  20.     select top 1
  21.         [Time], [Temp_Front], [Temp_Center], [Temp_Back]
  22.     from
  23.         @TestData
  24.     order  by
  25.          [Time] asc    
  26. )
  27. select top 1
  28.     [t].[Time], [t].[Temp_Front], [t].[Temp_Center], [t].[Temp_Back]
  29. from
  30.     @TestData   as [t]
  31. cross join
  32.     [min]       as [m]
  33. where
  34.         ([t].[Time]         <>  [m].[Time])
  35.     and [t].[Temp_Front]    >   [m].[Temp_Front]           
  36.     and [t].[Temp_Center]   >   [m].[Temp_Center]
  37.     and [t].[Temp_Back]     >   [m].[Temp_Back];
RAW Paste Data