1

我有一个问题,我不知道如何克服。我需要根据组内的字段过滤水晶报表中的我的组。不仅如此,我还需要它根据同一组内该字段中是否有两个不同的值来过滤组。例如,假设我有一个理事会的问题和投票表。对于包含问题名称和投票(是、否或弃权)的问题,每次投票有一个条目。我将按问题名称对表格进行分组,并且我想过滤组以仅显示投票分为“是”和“否”的问题(即没有弃权和非一致)。我该怎么做呢?

4

1 回答 1

0

您输入到分组顶层的数据需要预先汇总,以显示哪些投票有多个不同的响应。无论您的后端数据源是什么,您都需要这样做。如果我要在 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 )

我会使用多个步骤提取数据(但如果您认为这更容易理解,请随意进行子查询):

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

然后我会回到那个,喂给水晶:

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
于 2016-04-13T16:39:04.257 回答