简体   繁体   English

Iseries i View项目

[英]Iseries i View project

I would like to do this in a View. 我想在视图中执行此操作。

I have a crystal reprt which uses the table ordertrans. 我有一个使用表ordertrans的水晶reprt。 This table contains data about the order. 该表包含有关订单的数据。 This is a MFG. 这是MFG。 company and so orders are often custom and each piece of the puzzle will be listed on this table. 公司等订单通常是自定义的,每个难题都会在此表中列出。 packing codes PDB. 包装代码PDB。 THE CR before was joining on the order number and record selecting on 001. I added record select also on PDB. 之前的CR加入了订单号,并在001上选择了记录。我也在PDB上添加了记录选择。 I want a view that will only select the PDB one time. 我想只选择一次PDB的视图。 If they have more than 1, it is very likely some sort of error or rare condition and not applicable to the report. 如果它们大于1,则很可能是某种错误或罕见情况,不适用于该报告。 The issue is that the second PDB is causing Format errors not in the report but in the EXCEL EXPORT. 问题是第二个PDB导致格式错误不是在报表中,而是在EXCEL EXPORT中。 I should like a view to use instead of the current one. 我希望使用一种观点来代替当前观点。 Although the current one does not select only the 001 or packing codes, I think in theory we can only select the 001 and pdb ones theres actually 3 such code i mention one for simplification. 尽管当前的代码并不只选择001或打包代码,但我认为从理论上讲我们只能选择001和pdb的代码,实际上我只列举了3个这样的代码以简化代码。

order# TRNCDE 订单号TRNCDE

123 001 123001
123 999 123 999
123 PDB 123个PDB
123 AAA 123 AAA
123 BBB 123 BBB
123 PDB 123个PDB

123 CCC 123 CCC

Assuming there's a line number or sequence number in ORDERTRANS, choose the lowest one for each unique order/trncde combination: 假设ORDERTRANS中有一个行号或序列号,请为每个唯一的订单/ trncde组合选择最低的:

with min as 
  (select order#, trncde, min(line#) as line#
   from ordertrans
   group by order#, trncde)
select *
from ordertrans o
  join min m on o.order#=m.order# and
                o.trncde=m.trncde and
                o.line#=m.line#
order by order#, trncde;

If there's no unique line number, time stamp or sequence number to help you distinguish the PDB rows from each other, consider trying RRN instead: 如果没有唯一的行号,时间戳或序列号来帮助您区分PDB行,请考虑尝试使用RRN:

with min as 
  (select order#, trncde, rrn(ordertrans) as line#
   from ordertrans
   group by order#, trncde)
select *
from ordertrans o
  join min m on o.order#=m.order# and
                o.trncde=m.trncde and
                rrn(o)=m.line#
order by order#, trncde;

RRN() will cause an index build, causing a performance hit. RRN()将导致建立索引,从而导致性能下降。 (according to Birgitta Hauser) (根据Birgitta Hauser的说法)

If there's no unique line number, time stamp or sequence number to help you distinguish the PDB rows from each other, consider generating a ROW_NUMBER(): 如果没有唯一的行号,时间戳或序列号来帮助您区分PDB行,请考虑生成ROW_NUMBER():

with min as 
(select order#, trncde, 
        ROW_NUMBER() OVER(PARTITION BY order# ORDER BY another_col) as pick
   from ordertrans
   group by order#, trncde
) 
select *
  from ordertrans o
  join min        m    on  o.order#=m.order# 
                       and o.trncde=m.trncde 
                       and m.pick = 1
  order by order#, trncde;

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

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