如何在SQL中将行合并为单行?
ex:SELECT distinct studentID, studentName, MathGrade, SciGrade from vStudentGrade;
输出:
StudentID studentName MathGrade SciGrade
1 Zed 89
1 Zed 98
期望的输出:
StudentID studentName MatheGrade SciGrade
1 Zed 89 98
答案 0 :(得分:2)
我想知道您使用什么标准对它们进行分组。我假设总是有NULL值和数字...因为匹配de示例,但更多细节会更好!
SELECT studentID, studentName, max(MathGrade), max(SciGrade) from vStudentGrade
group by studentID, studentName, MathGrade, SciGrade
希望这有助于或指导您找到解决方案:)