簡體   English   中英

如何在SQL查詢中添加來自不同行的數據並將其顯示為一行的列

[英]How to add data from different rows and display them as columns of one row in sql query

我是SQL查詢字段中的新手,但可以進行一些查詢。 我想在表行中添加相關數據,並在同一列中顯示它們。 這是包含數據的表:

在此處輸入圖片說明

任何幫助將不勝感激。 提前致謝

如果實際上只有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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM