MIN& MAX在SQL Server中

时间:2015-08-18 18:24:55

标签: sql-server

slno    Date        In          Out        Hours      
---------------------------------------------------
  1     2015-08-17   5:32 PM    9:32 PM    04:00:00 
  2     2015-08-17  10:33 PM   12:00 AM    01:27:00 
  3     2015-08-18   5:31 PM    9:00 PM    03:29:00 
  4     2015-08-18  10:00 PM   12:01 AM    02:01:00 

我需要像这样的结果

slno    Date          In          Out        Hours    
-----------------------------------------------------
 1      2015-08-17    5:32 PM     12:00 AM   05:27:00     
 2      2015-08-18    5:31 PM     12:01 AM   05:30:00

请帮我解决这个问题。

1 个答案:

答案 0 :(得分:0)

你可能正在寻找这样的东西:

select row_number() over (order by date), X.in, X.out, convert(time, out - in)
from (
  select date, min(in) as in, max(out) as out
  from yourtable
  group by date
) X

没有对此进行测试,因此它可能不是100%准确,但你应该明白这一点。