1

各 ID の合計行数と、ID でグループ化された「FN%」と「W%」の成績の数の両方をカウントする SQL クエリを作成しようとしています。これらの数値が等しい場合、学生はすべて「FN%」またはすべて「W%」のいずれか、または両方の組み合わせのみを持っています。

「FN%」または「W%」の統計しかないすべての ID のリストが必要です

例 id # 683 & 657 はクエリの結果セットになりますが、603、781 & 694 はそうではありません

   id stat
  683 WF
  683 WF
  683 WF
  683 WF
  683 W
  683 W
  657 W
  657 W
  657 W
  657 W
  781 B+
  781 IP
  781 WP
  781 WP
  603 FN
  603 FN
  603 F
  603 FN
  603 FN
  694 B
  694 B+
  694 CI
  694 LAB
  694 WF
  694 WF

出力例:

683
657

4

4 に答える 4

0

xxxx は、処理するこの情報を保持する一時テーブルです.....

select id, fullname, count(id) ttl 
from xxxx 
group by id, fullname 
into temp www with no log;


select id, fullname, count(id) ttl_f 
from xxxx 
where grd like 'FN%' or grd like 'W%' 
group by id, fullname 
into temp wwww with no log;


select www.id, www.fullname 
from www, wwww 
where www.id = wwww.id and www.ttl = wwww.ttl_f;
于 2009-03-27T18:39:24.817 に答える
0

その説明は頭が痛くなる。これらの 2 つのセットの結合をお探しですか?

  • 「W%」に一致する統計のみを持つ ID
  • 「FN%」に一致する統計のみを持つ ID

その場合は、各セットのサブクエリを持つ UNION クエリにします。

于 2009-03-27T18:39:56.313 に答える
0

これは元の質問に対して書かれました:

select first 50
c.id,
(select trim(fullname) from entity where id = c.id) fullname,
count(*),
(select count(*) from courses where id = c.id and grd like 'FN%') FN,
(select count(*) from courses where id = c.id and grd like 'W%') W
from courses c
group by 1

名前を取得するためのサブクエリは、何らかの理由で結合を使用するよりもはるかに高速です。

編集: 以下は yukondude の回答と同じ動作をしますが、HPUX / Informix v10.00.HC5 ボックスでより優れたパフォーマンスを発揮します。

select c.id
from courses c
where not exists (
        select id
        from courses
        where (grd not like 'W%' and grd not like 'FN%')
        and id = c.id
)
group by 1
于 2009-03-27T19:19:36.810 に答える