[英]Query to select values from different rows and add them as columns to another table
[英]How to add data from different rows and display them as columns of one row in sql query
如果实际上只有3个问题,并且假设表名为“学生”,则可以执行以下操作:
select studentid AS Student,
(select Questionpoints from Student where studentid = a.studentid and Questionid = 8) AS Qn1,
(select Questionpoints from Student where studentid = a.studentid and Questionid = 9) AS Qn2,
(select Questionpoints from Student where studentid = a.studentid and Questionid = 10) AS Qn3
from Student as a
group by studentid;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.