mysql server 2008监视工作人员的输出

时间:2017-09-01 06:52:33

标签: sql-server sql-server-2008

我有一个问题要问:

Time     Pass    Fail
-------------------------
08:30    10       2
09:30    12       1
10:30    20       0
11:30    30       40

我需要结果:

   08:30       09:30       10:30       11:30
 Pass Fail   Pass Fail    Pass Fail   Pass Fail
  10   2      12   1       20   0      30   40

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

最近,你可以得到:

declare @x table(
  [Time] time,
  [Pass] smallint,
  [Fail] smallint
)

insert into @x values ('08:30', 10, 2),('09:30', 12, 1),('10:30', 20, 0),('11:30', 30, 40)

select case when [Time] = '08:30' then Pass end As [Pass 08:30],
   case when [Time] = '08:30' then Fail end As [Fail 08:30],
   case when [Time] = '09:30' then Pass end As [Pass 09:30],
   case when [Time] = '09:30' then Fail end As [Fail 09:30],
   case when [Time] = '10:30' then Pass end As [Pass 10:30],
   case when [Time] = '10:30' then Fail end As [Fail 10:30],
   case when [Time] = '11:30' then Pass end As [Fail 11:30],
   case when [Time] = '11:30' then Fail end As [Fail 11:30]
from @x