将行转换为列 [英] Convert rows in to columns
问题描述
TestID Testname备注
TestID Testname Remarks
1 Quartely "Do you have ção":"Algodão"
2 Halferly "Do you have próximo":"Não"
3 Annually "Do you have Irá Ajudar":"No"
从上面我想要输出如下
from the above i want output as follows
TestId Testname Do you have ção Do you have próximo Do you have Irá Ajudar
1 Quartely Algodão Não No
我的sql查询如下
My sql query as follows
SELECT A.Test_id,B.Testname,C.Remarks from studendetails
innerjoin tblstduent on B.Testid=C.Testid
where b.Testid IS NOT NULL
来自我上面的SQL查询的
我必须要做哪些更改得到以上输出
我尝试过:
TestID Testname备注
1四分之一你有ção:Algodão
2 Halferly你有próximo:Não
3每年你有IráAjudar:没有
来自上面的i想要输出如下
TestId Testname你有ção你有próximo你有IráAjudar
1QuartelyAlgodãoNãoNo
我的sql查询如下
SELECT A.Test_id,B.Testname,C.Remarks from studendetails
innerjoin tblstduent on B.Testid = C.Testid
其中b .Testid IS NOT NULL
来自我上面的sql查询我必须做出哪些更改才能获得上面的输出
from my above sql query what changes i have to made to get the above output
What I have tried:
TestID Testname Remarks
1 Quartely "Do you have ção":"Algodão"
2 Halferly "Do you have próximo":"Não"
3 Annually "Do you have Irá Ajudar":"No"
from the above i want output as follows
TestId Testname Do you have ção Do you have próximo Do you have Irá Ajudar
1 Quartely Algodão Não No
My sql query as follows
SELECT A.Test_id,B.Testname,C.Remarks from studendetails
innerjoin tblstduent on B.Testid=C.Testid
where b.Testid IS NOT NULL
from my above sql query what changes i have to made to get the above output
推荐答案
见这里:使用PIVOT和UNPIVOT | Microsoft Docs [ ^ ]
你可以从
You could start with something like
SELECT [Quartely], [Halferly], [Annually]
FROM ( SELECT testname, remarks
FROM YourTable) AS a
PIVOT ( MAX(remarks)
FOR testname IN ([Quartely], [Halferly], [Annually])) AS b
但是,为了得到答案,你需要根据的位置拆分例如结果:
字符
这篇关于将行转换为列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!