1
我有5個不同的表,如圖中所示。如何將行轉換爲列並將其添加到結果集中
我可以將它們結合使用該查詢,但我想添加書籍讀取日誌,使用書名作爲列名到該表中。 我用不同的顏色在圖片中顯示我的表格。
select dbo.Users.name+' '+dbo.Users.surname AS name_surname,
dbo.Student_Facebook_Data.likes,
dbo.Student_Facebook_Data.posts,
dbo.Student_Facebook_Data.comments,
dbo.Attendance.absence,dbo.Attendance.physical_presence,
dbo.Attendance.virtual_presence
from dbo.Users inner join dbo.Student_Facebook_Data on dbo.Users.id=dbo.Student_Facebook_Data.student_id
inner join dbo.Attendance on dbo.Users.id=dbo.Attendance.student_id
我試過了查詢,但這些都沒有解決我的問題:如果你的數據庫是SQL Server 2005或更高
select dbo.Users.name+' '+dbo.Users.surname AS name_surname ,dbo.Student_Log.content_id
from dbo.Student_Log inner join
dbo.Users on dbo.Student_Log.student_id=dbo.Users.id
select distinct(material_name)
from dbo.Material_Detail inner join
dbo.Student_Log on dbo.Student_Log.content_id=convert(varchar,dbo.Material_Detail.id)
select distinct(material_name)
from dbo.Material_Detail inner join
dbo.Student_Log on dbo.Student_Log.content_id=convert(varchar,dbo.Material_Detail.id)