水晶报表-分组依据 [英] Crystal Reports - Group By

查看:118
本文介绍了水晶报表-分组依据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Visual Studio 2008,并希望在报表中显示以下SQL查询:

I'm using Visual Studio 2008 and would like to present the following SQL query in a report:

select name, count(*) from mytable group by name;

我可以通过创建本质上是上述查询的数据集(由名称列组成)来实现此目的和计数),但是为该查询创建额外的数据集似乎过头了。我宁愿做我对项目中其他报告所做的事情,即拥有整个表的数据集:

I can achieve this by creating a dataset that is essentially the above query (consisting of columns 'name' and 'count'), however it seems overkill to create an additional dataset just for this query. I'd rather do what I've done with other reports in my project and that is have a dataset that is the entire table:

select * from mytable;

然后使用Crystal Report功能执行分组。但是,我找不到进行这种分组的方法。我认为这可能吗?这样一来,我就可以将数据集重用于项目中的其他区域,而不必为每个报表创建唯一的数据集。

And then use Crystal Report features to perform the grouping. Howver I can't find a way to do this grouping. I assume this is possible? This would allow me to reuse the dataset for other areas in the project rather than having to create a unique dataset for each report.

推荐答案

分组字段

不编写SQL查询,就可以从表中对数据进行分组。

Without Writing SQL query, you can group the Data from the table.

在字段资源管理器中,您可以右键单击组名字段,然后选择组专家。

In Field Explorer, you can find 'Group Name Fields' Right Click and Select 'Group Expert'.

选择后,您将得到一个组专家对话框,其中显示了在数据表中找到的字段。选择要分组的字段名称。
(此处选择了项目名称)

After selecting, you will get a Group Expert Dialog Box, which shows the Fields found in your datatable. Select a Field Name which you want to group. (Here I selected 'Project Name')

您也可以在该字段下创建子组,将组划分为A组,B组。

You can also create Sub-Groups under that field, the Groups ll be classified as Group A, Group B.

现在,您可以自动在水晶报表中找到添加的组字段!
分组已完成!

Now you can find Group Fields added in your crystal report automatically ! Grouping is Done !

计数字段

要计数报表中没有记录或字段,则需要添加新的运行总计字段

To Count the no of records or fields in a report, you need to add a new 'Running Total Fields'

添加要计数的字段。

添加字段后,将摘要类型更改为Count,然后按OK。

After adding the Field Change the 'Type of Summary' to Count, and press OK.

将此总字段添加到您需要的区域中的报表中(组页脚将为建议)。

Add this Total Field to your report in the area where you need (Group Footer will be advisable).

现在无需编写任何SQL查询就可以对字段名进行分组和计数。

Now find your Field Name is Grouped and Counted without writing any SQL Query.

希望这对您有所帮助,如果有的话,留下评论!

Hope this ll help you, Leave comments if any !

这篇关于水晶报表-分组依据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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