简体   繁体   English

过滤水晶报告中的分组记录

[英]Filtering grouped records in crystal reports

I have an issue that I'm not sure how to overcome. 我有一个问题,我不确定如何克服。 I need to filter a my groups in crystal reports based on a field within the group. 我需要根据组内的字段过滤水晶报表中的我的组。 Not only that I need it to filter the groups based on if there are two different values in this field within the same group. 不仅如此,我还需要根据同一组中此字段中是否存在两个不同的值来过滤组。 For example, say I have a table of issues and votes for a council. 例如,假设我有一个问题表,并为理事会投票。 There is one entry per vote on an issue containing the issue name and the vote cast (either yes, no, or abstain). 在包含问题名称和投票的问题上,每个投票有一个条目(是,否或弃权)。 I will group the table by issue name and I want to filter the groups to show only the issues with a vote split between yes and no (ie no abstains and not unanimous). 我将按照问题名称对表进行分组,并且我想过滤组以仅显示在是和否之间进行投票分割的问题(即没有弃权而不是一致)。 How do I go about doing this? 我该怎么做呢?

The data you're feeding into the top-level of the grouping needs to be pre-aggregated so as to show which Votes have multiple different responses. 您要加入到分组顶层的数据需要预先聚合,以便显示哪些投票有多个不同的回复。 You'd need to do this in whatever your back-end data source is. 无论您的后端数据源是什么,您都需要这样做。 If I were to do it in SQL, eg, given the tables: 如果我在SQL中这样做,例如,给定表:

create table dbo.Issues (
IssueID int identity(1,1) not null ,
constraint pkc_Issues primary key clustered ( IssueID ) ,
IssueText varchar(1000) )

--Note - not putting anything unique on VoterName because there may be 2 Joe Blows in the voter population.
create table dbo.Voters (
VoterID int identity(1,1) not null ,
constraint pkc_Voters primary key clustered ( VoterID ) ,
VoterName varchar(512) not null ) )

create table dbo.Votes (
VoteID int identity(1,1) not null ,
constraint pkn_Votes primary key nonclustered ( VoteID ) ,
VoterID int not null ,
constraint fk_VoterID@Votes foreign key ( VoterID ) references dbo.Voters ( VoterID ) ,
IssueID int not null ,
constraint fk_IssueID@Votes foreign key ( IssueID ) references dbo.Issues ( IssueID ) ,
constraint uci_IssueID_VoterID@Votes unique clustered ( IssueID , VoterID ) ,
VoteResponse varchar(16) null )

I'd pull the data using multiple steps (but feel free to do subqueries, if you think that's more understandable): 我会使用多个步骤来提取数据(但如果您认为更容易理解,可以随意做子查询):

select IssueID , Count(VoteResponse) as ResponseCount
into #hasMultiple from (select distinct IssueID , VoteResponse from Votes)

I'd then join back to that, to feed to Crystal: 然后我再加入到那里,以反馈给Crystal:

select dbo.Issues.IssueID ,
dbo.Issues.IssueText ,
cast(case when #hasMultiple.ResponseCount > 1 then 1 else 0 end as bit) as HasMultiple ,
dbo.Votes.VoteID ,
dbo.Votes.VoterID ,
dbo.Votes.VoteResponse ,
dbo.Voters.VoterName
from dbo.Issues
inner join dbo.Votes
on dbo.Issues.IssueID = dbo.Votes.IssueID
left join dbo.Voters
on dbo.Votes.VoterID = dbo.Voters.VoterID
left join #hasMultiple
on dbo.Issues.IssueID = #hasMultiple.IssueID

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM