我一直试图在我可以抓取的谷歌所有结果中了解 PIVOT 事物的不同方面。我没有运气翻译我的。:(
我想知道我们如何翻译这张表
+-------------+------------------------------+-------------+-------+
| Question | AnswerText | AnswerText2 | COUNT |
+-------------+------------------------------+-------------+-------+
| Answer this | Please select 'No' | No | 13 |
| Answer this | Please select 'Yes' | No | 1 |
| Answer this | Please select 'Yes' and 'No' | No | 12 |
| Answer this | Please select 'Yes' | Yes | 13 |
| Answer this | Please select 'Yes' and 'No' | Yes | 14 |
+-------------+------------------------------+-------------+-------+
我将这个 TSQL 用于上表
SELECT q.QuestionText as Question, a.AnswerText, pa.AnswerText2, COUNT ( pa.AnswerText2 ) COUNT
FROM Answer a
JOIN Question q on a.QuestionId = q.QuestionId
LEFT JOIN ParticipantAnswer pa on pa.AnswerId = a.AnswerId
LEFT JOIN Participant p on p.ParticipantId = pa.ParticipantId
WHERE q.QuestionId = 103
AND a.AnswerTypeId = 2
GROUP BY q.QuestionText, a.AnswerText, pa.AnswerText2
进入类似的东西
+--------------------------------------------+---------------------+
| Question | AnswerText | YES | NO |
+--------------------------------------------+---------------------+
| Answer this | Please select 'No' | 0 | 13 |
| Answer this | Please select 'Yes' | 13 | 1 |
| Answer this | Please select 'Yes' and 'No' | 14 | 12 |
+--------------------------------------------+---------------------+
我希望有人能帮助我。:)
非常感谢!
最好的祝福!