在SQL Server中按一栏汇总 [英] Roll up by one column in sql server

查看:91
本文介绍了在SQL Server中按一栏汇总的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友

我希望仅按表的列汇总查询,其余部分应按原样显示.
但是当我按条款在分组中使用它们时,我面临的汇总问题将应用于表的每一列.
有人可以提出解决方案吗?

Hi friends

I want ot rollup my query by only column of the table and rest should come as it is.
But the problem i am facing the rollup is applied on each column of the table when i am using them in the group by Clause .
Can anyone please suggest a solution?

推荐答案

检查一下:


http://chiragrdarji.wordpress.com/2008 /09/09/group-by-cube-rollup-and-sql-server-2005/ [
Check this out :


http://chiragrdarji.wordpress.com/2008/09/09/group-by-cube-rollup-and-sql-server-2005/[^]


您使用的是哪个版本的SQL Server使用吗?
在SQL Server 2008上,您可以使用分区来汇总任何列.

Which version of SQL server are you using?
On SQL Server 2008 you can rollup any column with partitioning.

select
     sum(aggregation_field) over (partition by GroupingField)
    ,otherfield2
    ,otherfield2
from
    dbo.table



您可以按其他字段分组,也可以完全不分组.
请注意,这样您将获得< aggregation_field>的总和.在每一行中.



You can group by another field or not group at all.
Note that with this you will get the sum of <aggregation_field> in every row.


这篇关于在SQL Server中按一栏汇总的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆