从sql查询中的值创建列

时间:2015-09-17 23:27:12

标签: sql sql-server sql-server-2008

我有这种格式的数据

employee_id date-time           activity
-------------------------------------------
23          01-06-2015 08:00    Punch In
23          01-06-2015 15:23    Punch Out
27          01-08-2015 08:12    Punch In
27          01-08-2015 14:13    Punch Out

我想要这个。

employee_id punch_in_time       punch_out_time
-------------------------------------------------
23          01-06-2015 08:00    01-06-2015 15:23
27          01-08-2015 08:12    01-08-2015 14:13

我想从表中编写一个视图来创建上面显示的数据格式。有人可以帮忙吗?我应该使用支点吗?

1 个答案:

答案 0 :(得分:2)

您可以使用条件聚合执行此操作:

C:\Users\junaid\Documents\GitHub\bucardo [master]> git checkout 'master@{2015-3-27 18:30:00}'
warning: Log for 'master' only goes back to Thu, 17 Mar 2015 18:08:03 -0500.
Note: checking out 'master@{2015-07-27 18:30:00}'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b new_branch_name

HEAD is now at cb4f95a... Start the cleanup of delete_rows()
C:\Users\junaid\Documents\GitHub\bucardo [(cb4f95a...)]>