有谁知道如何在快速报告中做清楚的统计吗?例如,我有一份报告:
Name sex
João m
João m
Maria f在正常计数中,结果是3,但我想要的结果是只接受不重复字段名的行数。在这种情况下,结果是2。有人能帮我吗?这只是个例子。我不能在SQL中按组操作,因为我有几个字段。
发布于 2017-08-17 15:00:35
我不擅长使用FastReport,但我在FastReport的官方论坛上找到了此页。
我认为您可以通过使其适应您的场景来更改这个示例(注意,语法可能需要一些调整)。
波段:
GroupHeader1 <Sex>
MasterData1 [Name, Sex, ...]
GroupFooter1 [GetDistinctCount]脚本(只处理按要计数字段排序的数据集):
var
LastValue : string;
DistinctCount : integer;
//create this event by double-clicking the event from the Object Inspector
procedure OnGroupHeader1.OnBeforePrint;
begin
if LastValue <> (<Datasetname."Sex">) then
Inc(DinstinctCount);
LastValue := <Datasetname."Sex">
end;
function GetDistinctCount: string;
begin
Result := IntToStr(DistinctCount);
end;基本思想是,每次字段值更改时,DistinctCount变量都会增加。
脚本(应该也适用于未排序的数据集):
var
FoundValues : array of string;
(* !!IMPORTANT!!
You need to initialize FoundValues array before to start counting: *)
SetLength(FoundValues, 0);
function IndexOf(AArray : array of string; const AValue : string) : integer;
begin
Result := 0;
while(Result < Length(AArray)) do
begin
if(AArray[Result] = AValue) then
Exit;
Inc(Result);
end;
Result := -1;
end;
//create this event by double-clicking the event from the Object Inspector
procedure OnGroupHeader1.OnBeforePrint;
begin
if(IndexOf(FoundValues, <Datasetname."Sex">) = -1) then
begin
SetLength(FoundValues, Length(FoundValues) + 1);
FoundValues[Length(FoundValues) - 1] := <Datasetname."Sex">;
end;
end;
function GetDistinctCount: string;
begin
Result := IntToStr(Length(FoundValues));
end;其基本思想是将找到的每个不同值添加到FoundValues数组中。
发布于 2017-08-17 12:47:02
您可以在没有GROUP BY的Firebird中这样做,如下所示:
DECLARE @T TABLE (ID INT IDENTITY (1,1), Name NVARCHAR(25) , Sex CHAR(1));
INSERT INTO @T VALUES
('Sami','M'),
('Sami','M'),
('Maria','F');
SELECT DISTINCT Name , Sex FROM @T您还可以创建一个View,然后在报表中使用它。
如果您真的需要在FastReport中这样做,则必须使用GroupHeader和GroupFooter。
怎么做到的?
您必须在OnBeforePrint事件中编写脚本。
procedure OnGroupHeader1.OnBeforePrint; 通过在“对象”检查器中双击事件创建此选项。
https://stackoverflow.com/questions/45735181
复制相似问题