SQL Server:将数据转换为水平或摘要的查询(没有聚合函数的数据透视)

时间:2013-11-03 08:17:09

标签: sql sql-server

我有如下所示的数据,我想创建一个摘要。请注意以下所需的输出。

数据

ID   TIMEIN               TIMEOUT
1    10/01/2013 8:00AM    10/01/2013 5:00PM
1    10/02/2013 8:00AM    10/01/2013 5:00PM
1    10/03/2013 8:00AM    10/01/2013 5:00PM
1    10/04/2013 8:00AM    10/01/2013 5:00PM
1    10/05/2013 8:00AM    10/01/2013 5:00PM
3    10/01/2013 8:10AM    10/01/2013 5:00PM
3    10/02/2013 8:02AM    10/01/2013 5:00PM
3    10/03/2013 8:04AM    10/01/2013 5:00PM
3    10/04/2013 8:20AM    10/01/2013 5:00PM
3    10/05/2013 8:03AM    10/01/2013 5:00PM
4    10/01/2013 8:10AM    10/01/2013 5:00PM
4    10/02/2013 8:02AM    10/01/2013 5:00PM
4    10/03/2013 8:04AM    10/01/2013 5:00PM
4    10/04/2013 8:20AM    10/01/2013 5:00PM
4    10/05/2013 8:03AM    10/01/2013 5:00PM

渴望输出

ID     10/01/2013     10/02/2013       10/03/2013       10/04/2013      10/05/2013
       IN     OUT     IN      OUT      IN      OUT      IN     OUT      IN   OUT
1     8:00AM  5:00PM  8:00AM  5:00PM   8:00AM  5:00PM   8:00AM  5:00PM  8:00AM  5:00PM
3     8:10AM  5:00PM  8:02AM  5:00PM   8:04AM  5:00PM   8:20AM  5:00PM  8:03AM  5:00PM
4     8:10AM  5:00PM  8:02AM  5:00PM   8:04AM  5:00PM   8:20AM  5:00PM  8:03AM  5:00PM

OR

ID     10/01/2013      10/02/2013       10/03/2013       10/04/2013      10/05/2013
1     8:00AM 5:00PM   8:00AM 5:00PM    8:00AM 5:00PM    8:00AM 5:00PM   8:00AM 5:00PM
3     8:10AM 5:00PM   8:02AM 5:00PM    8:04AM 5:00PM    8:20AM 5:00PM   8:03AM 5:00PM
4     8:10AM 5:00PM   8:02AM 5:00PM    8:04AM 5:00PM    8:20AM 5:00PM   8:03AM 5:00PM

如何使用提供的数据获得此输出?

0 个答案:

没有答案