如何旋转以下 SELECT 语句:
SELECT sc.CID,
sc.CodeName as OverviewText,
scRAG.CodeName as RAGStatusText
FROM StatusCode sc
LEFT OUTER JOIN ProjectOverview po
ON sc.CID = po.ProjectOverviewCID
AND po.ProjectId = 180
LEFT OUTER JOIN StatusCode scRAG
ON po.RAGStatusCID = scRAG.CID
WHERE sc.SCID = 18
这样的语句产生如下结果集:
CID OverviewText RAGStatusText
--- ------------ -------------
153 Cost Green
154 Requirements Yellow
155 Schedule NULL
156 Technical NULL
157 Testing NULL
但是,我希望它返回包含 10 个值的一行,如下所示:
----------------------------------------------------------------------------------------------
| Cost | Green | Requirements | Yellow | Schedule | NULL | Technical | NULL | Testing | NULL |
----------------------------------------------------------------------------------------------
我可以转向CID
吗?
我不确定这是否正是您想要的。但它给了你预期的结果。请注意,您可以根据需要重命名列。