Sybase IQ 12.7 User Manual

Page of 212
 4 章    OLAP の使用
パフォーマンス&チューニング・ガイド
91
このクエリ指定では、ウィンドウ句が
 ORDER BY 句の前にあることに注意し
てください。ウィンドウ句を使用するときには、次の制限が適用されます。
インラインのウィンドウ指定に
 PARTITION BY 句を含めることはできま
せん。
ウィンドウ句で指定されるウィンドウにウィンドウ・フレーム句を含める
ことはできません。たとえば、
 に次のように
記述されています。
<WINDOW FRAME CLAUSE> ::=
<WINDOW FRAME UNIT>
<WINDOW FRAME EXTENT>
インラインのウィンドウ指定にもウィンドウ句のウィンドウ指定にも
ウィンドウ順序句を含めることができますが、両方に含めることはできま
せん。たとえば、
 に次のように記述されてい
ます。
<WINDOW ORDER CLAUSE> ::= <ORDER SPECIFICATION>
例:
 複数の関数で使用されるウィンドウ
1 つの名前付きウィンドウを定義しておき、そのウィンドウに基づいて複数の
関数を計算することもできます。具体的な例を次に示します。
SELECT p.id, p.description, s.quantity, s.ship_date,
SUM(s.quantity) OVER ws1, MIN(s.quantity) OVER ws1
FROM sales_order_items s JOIN product p ON (s.prod_id =
p.id) WHERE s.ship_date BETWEEN '1994-05-01' AND
'1994-08-31' AND  s.quantity > 40 window ws1 AS
(PARTITION BY prod_id ORDER BY ship_date rows
between unbounded preceding and current row) 
ORDER BY p.id;
このクエリの結果セットを次に示します。
ID
description
quantity
ship_date
sum
min
---
-----------
--------
-----------
---
---
302
Crew Neck
60
1994-07-02
60
60
400
Cotton Cap
60
1994-05-26
60
60
400
Cotton Cap
48
1994-07-05
108
48
401
Wool cap
48
1994-06-02
48
48
401
Wool cap
60
1994-06-30
108
48
401
Wool cap
48
1994-07-09
156
48
500
Cloth Visor
48
1994-06-21
48
48
501
Plastic Visor
60
1994-05-03
60
60
501
Plastic Visor
48
1994-05-18
108
48
501
Plastic Visor
48
1994-05-25
156
48
501
Plastic Visor
60
1994-07-07
216
48
601
Zipped Sweatshirt
60
1994-07-19
60
60
700
Cotton Shorts
72
1994-05-18
72
72
700
Cotton Shorts
48
1994-05-31
120
48