我试图从 SQL 2008 查询中生成以下输出 -
JobID | Repair & Reshape | Refit Stripped Parts | Polishing
1000 | true | true | false
1001 | true | true | false
1002 | true | true | false
1003 | true | true | false
1004 | true | true | false
我拥有的表结构是 -
工作详情
ID - PK Auto increment
JobID - Int (Joined to Jobs table)
PhaseID - String (joined to JobPhases table)
工作阶段
ID - PK String
Name - VarChar(150)
到目前为止,我有 -
SELECT JobID, [0], [1], [2], [3], [4], [5], [6], [7]
FROM
(
SELECT JobID, PhaseID, [x] = 1 FROM JobDetails
) JobDetails
PIVOT
( SUM(x)
FOR PhaseID IN ([0], [1], [2], [3], [4], [5], [6], [7])
) pvt
但不确定如何用作业阶段名称替换 0-7 等?
干杯