我有这样的桌子
ID TimeStamp Statement Action
8082837636688904709 2012-07-23 16:03:25.000 UPDATE Skill name="French" SET state="1" 1
8082837636688904709 2012-07-23 16:03:25.000 UPDATE Skill name="French" SET state="2" 2
我想像这样转置它:
ID TimeStamp UndoStatement RedoStatement
8082837636688904709 2012-07-23 16:03:25.000 UPDATE Skill name="French" SET state="1" UPDATE Skill name="French" SET state="2"
这是我的查询:
SELECT ID, Timestamp, [UndoStatement], [RedoStatement]
FROM (
SELECT ID, TimeStamp, Statement, Action From Transactions) a
PIVOT
(
MAX(Statement) FOR Statement IN ([UndoStatement], [RedoStatement])
) as pvt
这就是我得到的
ID UndoStatement RedoStatement
8082837636688904709 NULL NULL
8082837636688904709 NULL NULL
谁能告诉我在做什么?