4

ここでは DB2 を使用して、iSeries 上のファイル内のデータについて話していました。

ファイル構造は次のとおりです。

Item     Textline    Text

12755    1           this item
12755    2           is no longer
12755    3           for sale
abc123   1           please use
abc123   2           another code
xyz987   1           obsolete

得ようとしている結果は

   Item     Text

   12755    this item is no longer for sale
   abc123   please use another code
   xyz987   obsolete

そのため、項目コードごとにグループ化され、テキスト行はいくつあっても合計されます。

ファイルをそれ自体に5回結合して(最大5行のテキスト行がある可能性があります)、最初にクエリで試してみましたが、うまく動作しませんでした。

私はSQLで試しましたが、慣れ親しんだコマンドをテキストで正しく動作させることができず、テキスト行を複製せずにそれらを一緒に追加する基準に苦労しています。

誰でもアイデアはありますか?

私の最後の手段は、このファイルを 5 回抽出して、各ファイルに異なるテキスト行だけを含め、アイテムに基づいてそれらをすべて照合し、そのように連結することです...しかし、それはどれほど面倒です :)

助けてください :)

4

5 に答える 5

1

V5R4

declare global temporary table qtemp.snippets
( item    varchar(10)
, seq     smallint
, words   varchar(30)
);

insert into qtemp.snippets  
  values 
   ('12755',  1, 'this item')
  ,('12755',  2, 'is no longer')
  ,('12755',  3, 'for sale')
  ,('abc123', 1, 'please use')
  ,('abc123', 2, 'another code')
  ,('xyz987', 1, 'obsolete')
;

with q(item, seq, words, phrase) as
(
    SELECT s.item
       , s.seq
       , s.words
       , s.words phrase 
    FROM qtemp.snippets s
    where s.seq = 1
    union all 
    SELECT s1.item
       , s1.seq
       , s1.words
       , q.Phrase || ' ' || s1.words phrase  
    FROM qtemp.snippets s1
    join q on s1.item = q.item
        and s1.seq = q.seq +1
)
select q.item, q.phrase from q 
join (
Select q.item, max(q.seq) maxseq from q
group by item
 ) q1 on q.item = q1.item and q.seq = q1.maxseq 
于 2014-10-30T16:13:57.160 に答える