我有一个存储员工登录信息的表
登录表的示例数据是
EmpID Status [Time]
100 SignIn 2013-03-07 11:41:44.473
101 SignIn 2013-03-07 10:41:44.473
100 SignOut 2013-03-07 12:41:44.473
101 SignOut 2013-03-07 11:41:44.473
101 SignIn 2013-03-08 11:41:44.473
我希望结果是
EmpID SignIn SignOut
100 2013-03-07 11:41:44.473 2013-03-07 12:41:44.473
101 2013-03-07 10:41:44.473 2013-03-07 11:41:44.473
101 2013-03-08 11:41:44.473 NULL
我尝试使用 PIVOT
Select EmpID,[SignIn],[SignOut]
from
(Select EmpId,status,LoginTime from Login)p
pivot
(
min(Logintime)
For status in ([SignIn],[SignOut])
)pvt
但是上面的查询省略了最后一行的Employee
101
有SignIn
时间但no SignOut
值
SQLFiddle用于生成表数据