0
使用SQL Server 2000比较日期和ID?
我想获得Table2.TimeIn Table2.TimeOut根据Table1.personid和也如果Table1.Date = Table3.Date那么它应该需要一个Table3.TimeIn,Table3.TimeOut。
3表
表1
ID Date
001 20090503
001 20090504
001 20090506
002 20090505
002 20090506
...等,
表2
ID TimeIn TimeOut
001 08:00:00 18:00:00
002 08:00:00 21:00:00
...等,
表3
ID Date TimeIn TimeOut
001 20090504 10:00:00 22:00:00
001 20090505 17:00:00 23:00:00
002 20090505 12:00:00 21:00:00
...等,
Select Table1.ID,
Table1.Date,
Table2.TimeIn,
Table2.TimeOut
from Table1
Inner Join Table2 on Table1.ID = Table2.ID
如果Table1.Date = Table3.Date那么就应该采取Table3.TimeIn,Table3.TimeOut其他Table2.TimeIn,Table2.Timeout
的预期输出
ID Date TimeIn TimeOut
001 20090503 08:00:00 18:00:00
001 20090504 10:00:00 22:00:00
001 20090506 08:00:00 18:00:00
002 20090505 12:00:00 21:00:00
002 20090506 08:00:00 21:00:00
...等,
如何为这种情况编写查询?
太快,我;打算发布这个相同的东西:) – 2009-10-06 14:08:16