使用SQL Server如何扣除小时condtion
表1
ID, MinTime, TotalTime, BreakTime
001, 04:00:00, 12:00:00, 00:30:00
002, 04:00:00, 03:00:00, 00:30:00
003, 08:00:00, 07:30:00, 03:30:00
004, 04:00:00, 03:59:59, 01:30:00
。
我要扣除TOTALTIME,课间时TOTALTIME> mintime
Condtion:
If Totaltime is greater than mintime then it should deduct the total hours, but it should Maintain the MinTime
例如:
Min time: 05:00:00
Total Time: 06:00:00
BreakTime: 01:30:00
总时间超过分钟时间越大,所以我们可以做(TOTALTIME,课间) ,它会给出像“04:30:00”这样的输出(不正确,因为它应该保持最短时间,所以它应该从休息时间扣除1小时)
预期输出
ID, MinTime, TotalTime, BreakTime DeductTime
001, 04:00:00, 12:00:00, 00:30:00 11:30:00 (TotalTime is Greater than mintime)
002, 04:00:00, 04:35:00, 01:00:00 04:00:00 (`Here TotalTime is greather than mintime, so it should deduct the breaktime from the total hours, but it should maintain the mintime also)`
003, 08:00:00, 07:30:00, 03:30:00 07:30:00 (TotalTime is less than mintime)
004, 04:00:00, 03:59:59, 01:30:00 03:59:59 (TotalTime is less than mintime)
如何查询上述条件。
需要查询帮助
有没有在你的例子一些矛盾选择。在最后三行`TotalTime`小于`MinTime`,但最后一行显示`DeductTime = 04:00:00 = MinTime`,而另外两行`DeductTime = TotalTime`。另外,什么数据类型用于时间值? – 2011-02-03 10:01:05