如何添加“总计”在行中(不在列中) [英] how to add "total" in row (not in column)
问题描述
嗨朋友们,
i为每周数据写了StoredProcedure
我希望行中的记录总和不是列
i不知道如何做,所以请检查我的sp并给我解决方案,
我的sP打印查询在这里,
hi friends,
i wrote StoredProcedure for weekly data
and i want to sum of records in row not column
i dont know how to do, so please check my sp and give me solution for this,
my sP's printed query is here,
select CourseName
, Sum([Week0]) as [Week Start - 20 Aug 10]
, Sum([Week1]) as [Week Start - 27 Aug 10]
, Sum([Week2]) as [Week Start - 03 Sep 10]
from (select CourseName
, case when StartDate >= '08/20/2010' and StartDate < '08/27/2010'
then COUNT(CourseName) else 0 end as [Week0]
, case when StartDate >= '08/27/2010' and StartDate < '09/03/2010'
then COUNT(CourseName) else 0 end as [Week1]
, case when StartDate >= '09/03/2010' and StartDate < '09/10/2010'
then COUNT(CourseName) else 0 end as [Week2]
from GL_BookingList bl
inner join GL_MasterPriceDefaultSelection mpds on bl.PriceItemId=mpds.PriceItemId
inner join GL_Course on GL_Course.CourseID= mpds.SelectionId
where (GL_Course.StartDate >= '08/16/2010' and GL_Course.StartDate < '09/11/2010')
group by CourseName,GL_Course.StartDate)as t
group by CourseName
CourseName ... WeekStart-20 Aug 2010。 .WeekStart-2010年8月27日。 .WeekStart-03 sep 2010
C语言。 。 。 。 。 。 。 。 。 。 。 2。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 .0。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 11
C ++。 。 。 。 。 。 。 。 。 。 。 0.2。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 .3。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 5
总计。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 4.。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 .3。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 。 16
_________
我想要这种类型的结果。请检查一下..
看不到dot..i把它换成格式,
CourseName...WeekStart-20 Aug 2010. . .WeekStart-27 Aug 2010. . .WeekStart-03 sep 2010
C language. . . . . . . . . . . 2. . . . . . . . . . . . . . . . . . . . . . . . . .0 . . . . . . . . . . . . . . . . . . . . 11
C++. . . . . . . . . . . .2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3 . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Total. . . . . . . . . . . . . . . . . 4. . . . . . . . . . . . . . . . . . . . . . . . .3 . . . . . . . . . . . . . . . . . . . . . 16
_________
i want this type of result. please check it..
don't see dots..i put it for format,
推荐答案
这里是简单的例子,可能是这对你有帮助。
Here is simple example, may be this will help you.
select institue.* from
(
select course_name
, Sum([Week0]) as [Week Start - 20 Aug 10]
, Sum([Week1]) as [Week Start - 27 Aug 10]
, Sum([Week2]) as [Week Start - 03 Sep 10]
from course group by course_name
) institue
union all
select 'total' as course_name,
, Sum([Week0]) as [Week Start - 20 Aug 10]
, Sum([Week1]) as [Week Start - 27 Aug 10]
, Sum([Week2]) as [Week Start - 03 Sep 10]
from course
说明:
- >在第一个查询中,您需要使用 SUM
将数据带入数周,并在 GROUP BY
中创建课程名称。
- >在第二个查询中,您需要使用 UNION ALL
并键入您的查询以仅获取一条记录,而不仅仅是SUM。
- >您需要使用表结构修改上述查询。
description :
--> In first query you need to bring your data with the use of SUM
for weeks and make course name in GROUP BY
.
--> In second query you need to user UNION ALL
and type your query to fetch only one record for only SUM of above all.
--> You need to modify above query with your table structure.
这篇关于如何添加“总计”在行中(不在列中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!