0

いいえを見つけようとしています。City = Liverpool の顧客であるテーブルからの予約の数。しかし、それは私に間違った結果を与えるようです。何がうまくいかなかったのでしょうか?

Tables : scustom, 
         sbook.
Data : ABCtable type scustom,
       BKcnt(4) type N.

Clear BKcnt.

Select * from scustom into ABCtable where city = 'Liverpool'.

  Select * from sbook.
    BKcnt = BKcnt + 1.
  Endselect.

  Write: / ABCtable-id,
             15 ABCtable-name,
             50 BKcnt.
ENDSELECT.
4

3 に答える 3

1

「何がうまくいかなかったのか」については、@knut の診断を参照してください。常に完全な sbook テーブルを選択するため、各顧客に同じ番号が表示されます。

このような質問については、集計、グループ化などはデータベースに任せたほうがよいでしょう。このバージョンを試してください:

report zz_count_sbook.

parameters: p_city type scustom-city lower case default 'Liverpool'.

data: id type scustom-id,
      name type scustom-name,
      count type i.

select customid name count(*) into (id,name,count)
       from scustom as c
       join sbook as b
       on b~customid = c~id
       where city eq p_city
       group by customid name.

  write: /    id,
           15 name,
           50 count.
endselect.
于 2014-07-07T05:48:29.500 に答える
0

あなたSelect * from sbook.には追加の条件が含まれていません。したがって、各ループで、 のエントリに接続されているものだけでなく、 sbook のすべてのエントリをカウントしますscustom

私はテーブルを知らないので、正しい選択を与えることができません。

You count は効率的ではありません。自分自身を数える必要はありません。

Tables : scustom, 
         sbook.
Data : ABCtable type scustom,
       BKcnt(4) type N.

Clear BKcnt.

Select * from scustom into ABCtable where city = 'Liverpool'.

  Select count(*) into  BKcnt from sbook
    where <???> = ABCtable-<???>.   "I don't know your keys, replace <???> with the correct fields.

  Write: / ABCtable-id,
             15 ABCtable-name,
             50 BKcnt.
ENDSELECT.

(私select countが正しいことを願っています。構文チェッカーで確認してください。少なくともABAPには集計機能があります!)

于 2014-07-06T18:19:54.300 に答える
-1

パフォーマンスを向上させるために、常にFOR ALL ENTRIES2 つのテーブルを結合するために使用します。

SELECT * FROM scustom INTO TABLE ABCtable WHERE city = 'Liverpool'

SELECT count(*) INTO  BKcnt FROM sbook FOR ALL ENTRIES IN ABCtable
WHERE <???> = ABCtable-<???>
于 2014-07-28T20:19:08.637 に答える