需要像我下面提到的输出表 [英] Need output table like i mentioned below
本文介绍了需要像我下面提到的输出表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
table
---------
ID Name subject marks
1 Murugan tamil 66
2 Raja tamil 82
3 Kumar tamil 74
4 Murugan English 71
5 Raja English 80
6 Kumar English 69
我需要这种类型的输出
i need this type output
Name tamil english
Murugan 66 71
Raja 82 80
Kumar 74 69
推荐答案
试试这个
Try this
CREATE TABLE #tbl_Language
(
ID BIGINT
,Name NVARCHAR(50)
,subject NVARCHAR(50)
,marks NVARCHAR(50)
)
INSERT INTO #tbl_Language
SELECT 1,'Murugan','tamil',66
UNION ALL
SELECT 2,'Raja','tamil',82
UNION ALL
SELECT 3,'Kumar','tamil',74
UNION ALL
SELECT 4,'Murugan','English',71
UNION ALL
SELECT 5,'Raja','English',80
UNION ALL
SELECT 6,'Kumar','English',69
SELECT Name ,tamil,English FROM
(Select Name, Subject, marks FROM #tbl_Language F) P
Pivot (MAX(Marks) For subject In (tamil,English)) as Pvt
select distinct(Obj1.Name),Obj2.Mark as 'Tamil',Obj3.Mark as 'English' from c Obj1 join c Obj2 on Obj1.Name=Obj2.Name and Obj2.Subject='Tamil' join c Obj3 on Obj1.Name=Obj3.Name and Obj3.Subject='English' order by Name
C是表名.
Obj1,Obj2,Obj3都是c的对象.
尝试此操作,即可确定所需的内容....
C is the Table Name.
Obj1,Obj2,Obj3 are all object of c.
Try this u vil get surely what u want....
这篇关于需要像我下面提到的输出表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文