![](/img/trans.png)
[英]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.