简体   繁体   English

Crystal Reports:显示一个字段的第一行,但在另一个字段上排序

[英]Crystal Reports: Showing first row for one field, but sorting on a different field

I have a report that shows three rows per item number with different transaction dates (itemnum, transdate). 我有一个报告,其中每个项目编号显示三行,并具有不同的交易日期(项目编号,交易日期)。 My issue is either the query or Crystal Reports. 我的问题是查询或Crystal Reports。 I want to sort on another field called UnusedMonths desc, but want to continue showing the most recent row for each ItemNum. 我想对另一个称为UnusedMonths desc的字段进行排序,但想继续显示每个ItemNum的最新行。 I am able to hide the older rows in Section Expert: 我可以在Section Expert中隐藏较旧的行:

   Previous ({ItemHistory.ItemNum}) = ({ItemHistory.ItemNum})

If I don't group ItemNum first, duplicate ItemNum will appear in the report. 如果我不首先对ItemNum进行分组,则重复的ItemNum将出现在报告中。 How do I fix this? 我该如何解决?

One option is to only select the rows with the latest transdate per itemnum. 一种选择是仅选择每个itemnum具有最新转换日期的行。 You can do this by creating a SQL Expression, let's call it {%MaxDate} , like: 您可以通过创建一个SQL表达式来实现此目的,我们将其称为{%MaxDate} ,例如:

case when "ItemHistory"."ItemNum" is null then null
else (select max(transdate)
      from itemhistory
      where itemnum = "ItemHistory"."ItemNum")
end

and then adding the following line to your report's selection formula: 然后将以下行添加到报表的选择公式中:

{ItemHistory.TransDate} = {%Maxdate}

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

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