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

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

问题描述

我正在使用 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;

我可以通过创建一个本质上是上述查询的数据集(由name"和count"列组成)来实现这一点,但是仅为这个查询创建一个额外的数据集似乎有点过头了.我宁愿做我在项目中对其他报告所做的事情,那就是拥有一个包含整个表格的数据集:

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'.

选择后,您将获得一个 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 !

计数字段

要计算报告中的记录或字段数,您需要添加一个新的Running Total Fields"

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

添加一个您要计算的字段.

Add a Field which you want to count.

添加字段后,将摘要类型"更改为计数,然后按确定.

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天全站免登陆