我需要总和2列。 [英] i need sum to 2 columns.
本文介绍了我需要总和2列。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的sql: -
选择 ROW_NUMBER() OVER ( ORDER BY t.studentid) AS SNo,max(t.roll_no) as RollNo,max (t.student) as 学生,
max([MST1( 10 )])< span class =code-keyword> as [ 1 MST1( 10 )], max([MST2( 20 )]) as [ 2 MST2( 20 )]
来自
(选择 t.studentid,' ' as roll_no,' ' as student,' < span class =code-string>' as subject,' ' as 当然,t.sem,
[ 1 ] as [MST1( 10 )],[ 2 ] as [MST2( 20 )]
from exammarksheet
pivot
(max(obtMarks) for ExamID in ([ 1 ],[ 2 ])) as t 其中(t.subjectid = 2 和 t.courseid = 1492 和 t.sem = 3 和 t.classesid = 17 和 t.sessionid = 20142015 )
union 全部
选择 distinct student.studentid,roll_no,student,subjectall.code as subject,course.code as course,exammarksheet.sem,' ' as a,' ' as a,' 学生的>'
内部 加入 exammarksheet student.studentid = exammarksheet.studentid
inner join course on student.courseid = course.courseid
inner join subjectall < span class =code-keyword> on exammarksheet.subjectid = subjectall.subjectid
where exammarksheet.subjectid = 2 exammarksheet.courseid = 1492 和 exammarksheet.sem = 3
和 exammarksheet.sessionid = 20142015 exammarksheet.classesid = 17 ) as t group by t.sem,t。 studentid
i需要[MST1(10)]和[MST2(20)]之和作为总计。
我该怎么做。
解决方案
在您想要的查询中尝试这个
([MST1( 10 )] + [MST2( 20 )]) 总计
here is my sql :-
select ROW_NUMBER() OVER (ORDER BY t.studentid) AS SNo,max(t.roll_no) as RollNo,max(t.student) as Student ,
max([MST1(10)]) as [1 MST1(10)],max([MST2(20)]) as [2 MST2(20)]
From
( select t.studentid,'' as roll_no,'' as student,'' as subject ,'' as course,t.sem ,
[1] as [MST1(10)],[2] as [MST2(20)]
from exammarksheet
pivot
(max (obtMarks) for ExamID in ([1],[2])) as t where (t.subjectid = 2 And t.courseid = 1492 And t.sem = 3 And t.classesid = 17 And t.sessionid = 20142015)
union all
select distinct student.studentid, roll_no,student ,subjectall.code as subject,course.code as course,exammarksheet.sem , '' as a,'' as a,'' as a from student
inner join exammarksheet on student.studentid=exammarksheet.studentid
inner join course on student.courseid=course.courseid
inner join subjectall on exammarksheet.subjectid=subjectall.subjectid
where exammarksheet.subjectid = 2 And exammarksheet.courseid = 1492 And exammarksheet.sem = 3
and exammarksheet.sessionid=20142015 And exammarksheet.classesid = 17 ) as t group by t.sem,t.studentid
i need sum of [MST1(10)] and [MST2(20)] as Total.
how can i do it.
解决方案
Try this in your query where you want
([MST1(10)] + [MST2(20)]) as Total
这篇关于我需要总和2列。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文