SQL将27个字段比较为1个字段

时间:2017-07-06 18:57:50

标签: sql substring concatenation ibm-midrange

我正在寻找文件中的重复记录有27个字段我需要比较它们是连续的有没有办法比较它们与每个输出的方式(一种方法来对记录格式进行子网格划分)数据)

我正在使用

Select RRN(a),
       RRN(b)
From   fileX a
Inner Join fileX b
    On RRN(a) < RRN(b)
       And a.FLD1 = b.FLD1
       And a.FLD2 = b.FLD2
       And a.FLD3 = b.FLD3
       And a.FLD5 = b.FLD5
       And a.FLD6 = b.FLD6
       And a.FLD7 = b.FLD7
       And a.FLD8 = b.FLD8
       And a.FLD9 = b.FLD9
       And a.FLD10 = b.FLD10
       And a.FLD11 = b.FLD11
       And a.FLD12 = b.FLD12
       And a.FLD13 = b.FLD13
       And a.FLD14 = b.FLD14
       And a.FLD15 = b.FLD15
       And a.FLD16 = b.FLD16
       And a.FLD17 = b.FLD17
       And a.FLD18 = b.FLD18
       And a.FLD19 = b.FLD19
       And a.FLD21 = b.FLD21
       And a.FLD22 = b.FLD22
       And a.FLD23 = b.FLD23
       And a.FLD24 = b.FLD24
       And a.FLD25 = b.FLD25
       And a.FLD26 = b.FLD26
       And a.FLD27 = b.FLD27

我想用

Select RRN(a),
       RRN(b)
From   fileX a
Inner Join fileX b
    On RRN(a) < RRN(b)
       And substr(A.RCDFMT, 100, 54) = substr(B.RCDFMT, 100, 54)

我知道我可以将它们连接在一起,但这仍然意味着输入所有的字段名称,我只想要一个更简洁的选择。

1 个答案:

答案 0 :(得分:0)

创建一个视图,将27个字段连接到一个字段中。

创建一个逻辑文件,其中27个字段连接成一个字段。

create view mylib/myview as 
select a.fld1 || a.fld2 || a.fld3 
...
 as allfld
from mylib/myfile.