水晶报表 - 分组依据
我正在使用 Visual Studio 2008,并希望在报告中呈现以下 SQL 查询:
select name, count(*) from mytable group by name;
我可以通过创建一个本质上是上述查询的数据集(由列“name”和“count”组成)来实现此目的,但是看起来仅仅为此查询创建额外的数据集就太过分了。我宁愿做我在项目中对其他报表所做的事情,即拥有一个包含整个表的数据集:
select * from mytable;
然后使用 Crystal Report 功能来执行分组。但是我找不到进行此分组的方法。我认为这可能吗?这将使我能够将数据集重复用于项目中的其他区域,而不必为每个报告创建唯一的数据集。
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;
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
分组字段
无需编写SQL查询,您就可以对表中的数据进行分组。
在字段资源管理器中,您可以找到“组名称字段”,右键单击并选择“组专家”。
选择后,您将看到一个组专家对话框,其中显示在数据表中找到的字段。选择要分组的字段名称。
(这里我选择了“项目名称”)
您还可以在该字段下创建子组,即组将被分类为A组、B组。
现在您可以找到自动添加到水晶报表中的组字段!
分组完成!
计数字段
要计算报告中的记录或字段数,您需要添加新的“运行总计字段”
添加您要计数的字段。
添加字段后,将“摘要类型”更改为“计数”,然后按“确定”。
将此总计字段添加到报告中您需要的区域(建议使用组页脚)。
现在发现您的字段名称已分组并计数,而无需编写任何 SQL 查询。
希望这对您有帮助,如果有的话请发表评论!
Grouping Fields
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')
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 !
Counting 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).
Now find your Field Name is Grouped and Counted without writing any SQL Query.
Hope this ll help you, Leave comments if any !
在水晶报表中,按“名称”字段添加分组,并在其中插入详细信息中任何字段的摘要,将摘要函数更改为“计数”。
In crystal reports, add group by 'name' field and insert there summary of any field from detail, changing summary function to 'count'.
在水晶中添加一个组字段;在此示例中,在名称字段上。
将详细信息插入组的页脚。
将计数函数插入组的页脚,根据记录唯一标识符进行计数。例如,如果同名多次出现,也可以使用不同的计数。
Add a group field in crystal; in this example on the name field.
Insert details into the footer of the group.
Insert a count function into the footer of the group, counting on the record unique identifiers. Can also use a distinct count if you have multiple occurences of the same name for example.
为了获得最佳性能,您确实应该在服务器端使用 GROUP BY。
创建一个向 Crystal Report 提供数据的视图。
您可以在 Crystal 中进行分组,但是您会遇到性能问题
随着报告查询的数据规模扩大。
这是一个设计决策,但从长远来看,它可以节省大量时间和客户处理。
我倾向于首先设计视图(WHERE 子句、GROUP BY 子句、SELECT 中的数据库函数)
然后是在数据库端准备好数据后的水晶报表。
我的建议是以终为始。
For optimal performance, you should really use GROUP BY on the server side.
Create a view that feeds data to your Crystal Report.
You can do grouping in Crystal, however you will encounter performance issues
as the data queried by your report scales up.
It is a design decision, but it saves lots of time and client processing in the long run.
I tend to design the view first (WHERE clause, GROUP BY clause, DB Functions in SELECT)
and then the Crystal Report after I have the prepared the data on the DB side.
My advice is to start with the end in mind.
如果可能,创建一个对数据集进行分组的数据库视图,然后在水晶报表中使用该视图。这是您在报告中尝试完成的任务的最简单且最易读的实现。
If possible, create a database view that groups the dataset and then use that view in the crystal report. This is the easiest and most readable implementation of what you're trying to accomplish in the report.