【发布时间】:2011-12-17 10:02:19
【问题描述】:
表格
ID Date Time
001 12/01/2011 08:00:00
001 12/01/2011 08:30:00
001 12/01/2011 11:30:00
001 12/01/2011 12:35:00
001 12/01/2011 03:30:00
001 12/01/2011 04:30:00
002 12/01/2011 08:30:00
002 12/01/2011 09:30:00
....
我想从表中选择intime、outtime、breakouttime、breakintime
Select id, date, min(time) as intime, max(time) as outtime from table group by id, date
上述查询适用于 intime 和 outtime,但我想为日期选择 break outtime 和 break intime。
例如 BreakOut 时间在 11:30:00 到 12:30:00 之间意味着查询应该检查从 11:00:00 到 01:00:00 之间的 min(Punchtime) 和 max(Punchtime) 的时间。
预期输出
Id Date intime outtime breakout breakin
001 08:00:00 04:30:00 11:30:00 12:35:00
002 08:30:00 09:30:00 null null 'so there is no punches between 11 to 1 for the break time, so break time should be null
如何查询上述条件
需要查询帮助
【问题讨论】:
-
你怎么知道 11:30 和 12:35 是休息时间?为什么不是 8:30 或 3:30?
标签: sql sql-server sql-server-2000