Crystal 报告零值

发布于 2024-09-28 09:24:49 字数 306 浏览 2 评论 0原文

嘿伙计们, 所以我有这份报告,我将其分为不同的年龄段。如果没有与年龄桶关联的行,我希望年龄桶的计数为零。所以我在数据库选择中做了一个外部连接,效果很好。但是,我需要根据数据库中的另一列添加一个组。

当我添加该组时,没有与之关联的行的年龄桶就会消失。我想这可能是因为我试图分组的列对于该行来说是空的,所以我在我的选择中添加了一个行号,然后按它分组(我基本上只需要按每一行分组,我可以不仅仅是详细说明...如果有必要,我可以对此进行更多解释)。但是添加行号后,没有数据的agebuckets仍然为空!当我删除我添加的这个组时,我会得到所有年龄段。

有什么想法吗?谢谢!!

Hey guys,
So I have this report that I am grouping into different age buckets. I want the count of an age bucket to be zero if there are no rows associated with this age bucket. So I did an outer join in my database select and that works fine. However, I need to add a group based on another column in my database.

When I add this group, the agebuckets that had no rows associated with them dissapear. I thought it might have been because the column that I was trying to group by was null for that row, so I added a row number to my select, and then grouped by that (I basically just need to group by each row and I can't just put it in the details... I can explain more about this if necessary). But after adding the row number the agebuckets that have no data are still null! When I remove this group that I added I get all age buckets.

Any ideas? Thanks!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

似梦非梦 2024-10-05 09:24:49

这是因为年龄组的外部连接并不也是其他任何年龄组的外部连接
组是 - 您只能保证每个数据集都有每个年龄组的一个,而不是每个[其他组]每个年龄组的一个。

因此,例如,如果您的另一个组是“区域”,则在外部连接到其余组之前,您需要从年龄范围表到区域表进行笛卡尔/交叉连接(以便获得年龄范围和区域的所有可能组合)你的数据集。

编辑 - 根据评论,如下所示的查询应该可以工作:(

select date_helper.date_description, c.case_number, e.event_number
from 
(select 0 range_start, 11 range_end, '0-10 days' date_description from dual union
 select 11, 21, '11-20 days' from dual union  
 select 21, 31, '21-30 days' from dual union  
 select 31, 99999, '31+ days' from dual) date_helper
cross join case_table c
left outer join event_table e
on e.event_date <= date_helper.range_start*-1 + sysdate 
and e.event_date > date_helper.range_end*-1 + sysdate
and c.case_number = e.case_number

假设它是需要分组到存储桶中的 event_date 。)

It's because the outer join to age group is not also an outer join to whatever your other
group is - you are only guaranteed to have one of each age group per data set, not one of each age group per [other group].

So if, for example, your other group is Region, you need a Cartesian / Cross join from your age range table to a Region table (so that you get every possible combination of age range and region), before outer joining to the rest of your dataset.

EDIT - based on the comments, a query like the following should work:

select date_helper.date_description, c.case_number, e.event_number
from 
(select 0 range_start, 11 range_end, '0-10 days' date_description from dual union
 select 11, 21, '11-20 days' from dual union  
 select 21, 31, '21-30 days' from dual union  
 select 31, 99999, '31+ days' from dual) date_helper
cross join case_table c
left outer join event_table e
on e.event_date <= date_helper.range_start*-1 + sysdate 
and e.event_date > date_helper.range_end*-1 + sysdate
and c.case_number = e.case_number

(assuming that it's the event_date that needs to be grouped into buckets.)

小梨窩很甜 2024-10-05 09:24:49

我无法理解你的问题。

我确实知道 Crystal Reports 的 NULL 支持在一些非常基本的方面缺乏。所以我通常尽量不依赖它。

解决这个问题的一种方法是在数据库查询中对年龄范围进行硬编码,例如:

  SELECT p.person_type
         , SUM(CASE WHEN 
               p.age <= 2 
               THEN 1 ELSE 0 END) AS "0-2"
         , SUM(CASE WHEN 
               p.age BETWEEN 2 AND 18 
               THEN 1 ELSE 0 END) AS "3-17"
         , SUM(CASE WHEN 
               p.age >= 18 
               THEN 1 ELSE 0 END) AS "18_and_over"
    FROM person p
GROUP BY p.person_type

这样您就一定能在想要零的地方得到零。

我意识到这不是对你的问题的直接回答。祝你好运。

I had trouble understanding your question.

I do know that Crystal Reports' NULL support is lacking in some pretty fundamental ways. So I usually try not to depend on it.

One way to approach this problem is to hard-code age ranges in the database query, e.g.:

  SELECT p.person_type
         , SUM(CASE WHEN 
               p.age <= 2 
               THEN 1 ELSE 0 END) AS "0-2"
         , SUM(CASE WHEN 
               p.age BETWEEN 2 AND 18 
               THEN 1 ELSE 0 END) AS "3-17"
         , SUM(CASE WHEN 
               p.age >= 18 
               THEN 1 ELSE 0 END) AS "18_and_over"
    FROM person p
GROUP BY p.person_type

This way you are sure to get zeros where you want zeros.

I realize that this is not a direct answer to your question. Best of luck.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文