我有一个查询问题:
对于任何给定的问题,IntakeQCID
我都有IntakeQCDetailID
很多问题和答案。现在我需要选择每个问题和答案放在单独的列上。
像这样的工作:
SSELECT IntakeQC.IntakeQCID, IntakeQC.PalletID, Max(CASE WHEN QCProductQuestions.QCQuestionID = 106 THEN CAST(Answer AS varchar(10)) ELSE '' END) AS ArrivalTemperature
FROM QCProductQuestions INNER JOIN
IntakeQCDetails ON QCProductQuestions.QCProductQuestionID = IntakeQCDetails.QCProductQuestionID INNER JOIN
IntakeQC ON IntakeQCDetails.IntakeQCID = IntakeQC.IntakeQCID INNER JOIN
QCQuestions ON QCProductQuestions.QCQuestionID = QCQuestions.QCQuestionID
WHERE (QCProductQuestions.Intake = 1) AND (IntakeQC.IntakeQCID = 9413) AND (IntakeQCDetails.Answer <> '')
Group By IntakeQC.IntakeQCID, IntakeQC.PalletID
这是输出:
如果我不这样做,如果一个特定的IntakeQCID
有 20 个 QC 问题,我会得到 20 行数据,我只想要一个..
然而问题是QCQuestions
我的范围内有 170+,我必须为每一个都做。有没有更优雅的方法来实现这一点?
任何帮助、想法或建议将不胜感激。