[英]How do I get two sums of two separate tables with no joint keys in a single crystal report?
I have data in two tables (see below for a sample) - how do I create a Crystal report (more of a "score card" really) displaying only sum(table1.column1) and sum(table2.column1) with no other details? 我有两个表中的数据(请参见下面的示例)-如何创建仅显示sum(table1.column1)和sum(table2.column1)的Crystal报表(实际上是“记分卡”的更多内容),而没有其他详细信息? When I try, one of the sums gets way too big, indicating it has been included in some inner loop in the calculations.
当我尝试时,总和之一变得太大,表明它已包含在计算的某些内部循环中。
Table1: 表格1:
Column1: Integer 列1:整数
Column2: Varchar(100) 第2栏:Varchar(100)
... ...
Table2: 表2:
Column1: Integer 列1:整数
Column2: Varchar(50) 专栏2:Varchar(50)
... ...
Note - there are no joint keys, the only relation between the tables is that they relate to the same business area. 注意- 没有联合键,表之间的唯一关系是它们与同一业务领域相关。
select t1.cnt, t2.cnt
from ( select count(*) cnt from table1 where... ) t1
, ( select count(*) cnt from table2 where... ) t2
If you want to avoid the sub-query approach, the only real route that I can think of is to use sub-reports. 如果您想避免使用子查询方法,那么我能想到的唯一真正的方法就是使用子报告。
2 ways I can think of: 我可以想到2种方式:
I answer this with the caveat that it will almost certainly be slower than simply using one query (as in Randy's answer), because Crystal Reports is not as efficient as the DB engine. 我要警告一下,这几乎肯定会比仅使用一个查询(如Randy的回答)要慢,因为Crystal Reports的效率不如DB引擎。 It's also probably going to be harder than maintain.
这也可能比维护困难。 Basically, while you certainly can do it this way, I'm not sure I would .
基本上,虽然您当然可以这样做,但我不确定是否可以 。
You could use two SQL Expression fields. 您可以使用两个SQL Expression字段。 Each field needs to return a scalar value.
每个字段都需要返回一个标量值。 You can correlate (link) each query with the main-report's query as well.
您还可以将每个查询与主报表的查询关联(链接)。
The first one obviously requires (1) a unique key in Table1 and (2) printing the values in the footer. 第一个显然需要(1)表1中的唯一键,以及(2)在页脚中打印值。 If those constraints won't work, two subreports should still work.
如果这些约束不起作用,则两个子报表仍应起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.