【发布时间】:2016-12-02 11:46:26
【问题描述】:
我有如下数据
| Name | Subject | Answer |
|:----------|:----------|:---------------------:|
|Pranesh |Physics |Numerical Problems |
|Pranesh |Physics |Other |
|Pranesh |Chemistry |Understanding Concepts |
|Pranesh |Chemistry |Organic chemistry reactions
|Pranesh |Maths |Lack of understanding |
|Pranesh |Maths |Insufficient practice |
|Pranesh |Maths |Other |
使用此 SQL 查询:
select *
from
(select
l.FullName Name, sq.Title Subject, cAns.Name Answer
from
Answer as sa
left join
Question AS sq on sq.ID = sa.QuestionID
left join
Master as cAns on cAns.ID = sa.AnswerID
left join
Profile as l on l.ID = sa.ProfileID) src
pivot
(max(Answer)
for Subject in ([Physics], [Chemistry], [Maths], [Biology],[ComputerScience], [CommonUnderstanding])) piv;
我可以得到如下数据
如何连接同一主题的答案栏并显示与上面的屏幕截图相同?
【问题讨论】:
-
预期输出应该是
标签: sql-server pivot concatenation