DL_MEM_DEBUG:  initializing options [trace,exceptions,log=stdout]
DL_FILE_DEBUG:  initializing options [trace]
DS73013 2.0.00  ODXSQL - Omnidex SQL                   Tue Jun 07 16:31:27 2005
(c) Dynamic Information Systems Corp.  1981-2005
LICENSEE: ** Trial Copy ** 


> ; SUMMARY      Unit test
> ;
> ; DESCRIPTION  This is one of the unit tests
> ;
> ; STATUS       These tests have been properly validated.
> ;
> ; KEYWORDS     unit test acceptance
> ;
> 
> ; <COMMON>
> connect star
[DATABASES=
STAR,STAR,FLATFILE,,,]
Connected to <filename> on instance 1, cursor 1
> set qualify_counts noparent
> ;
> ;  Sampling of tests for 3.5 features.
> ;
> ;
> ; <SECTION=COUNT()>
> ;
> ;Tests optimized count()
> ;
> ; <TEST=C1>
> ;1
> select count(*) from products
[SELECT_ITEMS=
1,Expr,"COUNT('*')",,UNS INT(4),,C STRING(11)]
[ORDER_BY=NONE]

COUNT('*')  
----------  
       100  
1 row returned
> ; <TEST=C2>
> ;2
> select count(sales_tax) from orders
[SELECT_ITEMS=
1,Expr,"COUNT(ORDERS.SALES_TAX)",,UNS INT(4),,C STRING(11)]
[ORDER_BY=NONE]

COUNT(ORDE  
----------  
       200  
1 row returned
> ; <TEST=C3>
> ;3
> select count(*) from activity \
 (cont) >   where initials = 'EFR' or tickler in ('MF', 'PC', 'RC')
[SELECT_ITEMS=
1,Expr,"COUNT('*')",,UNS INT(4),,C STRING(11)]
[ORDER_BY=NONE]

COUNT('*')  
----------  
         6  
1 row returned
> ; Test reuse
> ; <TEST=C3r>
> ;4
> select count(*) from activity \
 (cont) >   where initials = 'EFR' or tickler in ('MF', 'PC', 'RC')
[SELECT_ITEMS=
1,Expr,"COUNT('*')",,UNS INT(4),,C STRING(11)]
[ORDER_BY=NONE]

COUNT('*')  
----------  
         6  
1 row returned
> ; <TEST=C4>
> ;5
> select count(p.product_no) \
 (cont) >   from orders o, products p \
 (cont) >   where o.product_no = p.product_no and \
 (cont) >         (o.quantity >= 10 or p.wholesale > 1000.00)
[SELECT_ITEMS=
1,Expr,"COUNT(P.PRODUCT_NO)",,UNS INT(4),,C STRING(11)]
[ORDER_BY=NONE]

COUNT(P.PR  
----------  
        80  
1 row returned
> ; <TEST=C5>
> ;6
> select count(*) from orders group by acct
[SELECT_ITEMS=
1,Expr,"COUNT('*')",,UNS INT(4),,C STRING(11)]
[ORDER_BY=NONE]

COUNT('*')  
----------  
       163  
        36  
         1  
3 rows returned
> ;
> ;
> ;Tests un-optimized count()
> ;
> ; <TEST=C6>
> ;7
> select count(*) from pmt_methods
[SELECT_ITEMS=
1,Expr,"COUNT('*')",,UNS INT(4),,C STRING(11)]
[ORDER_BY=NONE]

COUNT('*')  
----------  
        10  
1 row returned
> ; <TEST=C7>
> ;8
> select count(mailflag) from prospects
[SELECT_ITEMS=
1,Expr,"COUNT(PROSPECTS.MAILFLAG)",,UNS INT(4),,C STRING(11)]
[ORDER_BY=NONE]

COUNT(PROS  
----------  
        10  
1 row returned
> ; <TEST=C8>
> ;9
> select count(p.product_no), count(o.acct) \
 (cont) >   from orders o join products p using (product_no) \
 (cont) >   where (o.quantity >= 10 or p.wholesale > 1000.00)
[SELECT_ITEMS=
1,Expr,"COUNT(P.PRODUCT_NO)",,UNS INT(4),,C STRING(11)
2,Expr,"COUNT(O.ACCT)",,UNS INT(4),,C STRING(11)]
[ORDER_BY=NONE]

COUNT(P.PR  COUNT(O.AC  
----------  ----------  
        80          80  
1 row returned
> ; Test reuse
> ; <TEST=C8r>
> ;10
> select -1 * (count(*) + 5) from activity \
 (cont) >   where tickler like 'C%'
[SELECT_ITEMS=
1,Expr,"-1 * COUNT('*') + 5",,DOUBLE(8),,C STRING(33)]
[ORDER_BY=NONE]

-1 * COUNT('*') + 5               
--------------------------------  
                      -99.000000  
1 row returned
> ; <TEST=C9>
> ;11
> select -1 * (count(*) + 5) from activity \
 (cont) >   where tickler like 'C%'
[SELECT_ITEMS=
1,Expr,"-1 * COUNT('*') + 5",,DOUBLE(8),,C STRING(33)]
[ORDER_BY=NONE]

-1 * COUNT('*') + 5               
--------------------------------  
                      -99.000000  
1 row returned
> ; <TEST=C10>
> ;12
> select 'counted ', count(quantity) from orders \
 (cont) >   where order_date > '01-01-1996' or quantity between 1 and 5 \
 (cont) >         or sales_tax < 4.00
[SELECT_ITEMS=
1,String,'counted ',,C STRING(9),,C STRING(9)
2,Expr,"COUNT(ORDERS.QUANTITY)",,UNS INT(4),,C STRING(11)]
[ORDER_BY=NONE]

counted   COUNT(ORDE  
--------  ----------  
counted          158  
1 row returned
> ;
> ;
> ; <SECTION=COUNT(DISTINCT)>
> ;
> ;Tests optimized count(distinct col)
> ;
> ; <TEST=CD1>
> ;13
> select count(distinct cost) from products
[SELECT_ITEMS=
1,Expr,"COUNT(DISTINCT PRODUCTS.COST)",,UNS INT(4),,C STRING(11)]
[ORDER_BY=NONE]

COUNT(DIST  
----------  
        57  
1 row returned
> ; <TEST=CD2>
> ;14
> select count(distinct order_date) from orders \
 (cont) >   where order_date > '01-01-1996' or quantity between 1 and 5 \
 (cont) >         or sales_tax < 4.00
[SELECT_ITEMS=
1,Expr,"COUNT(DISTINCT ORDERS.ORDER_DATE)",,UNS INT(4),,C STRING(11)]
[ORDER_BY=NONE]

COUNT(DIST  
----------  
        68  
1 row returned
> ; Test reuse
> ; <TEST=CD2r>
> ;15
> select count(distinct order_date) from orders \
 (cont) >   where order_date > '01-01-1996' or quantity between 1 and 5 \
 (cont) >         or sales_tax < 4.00
[SELECT_ITEMS=
1,Expr,"COUNT(DISTINCT ORDERS.ORDER_DATE)",,UNS INT(4),,C STRING(11)]
[ORDER_BY=NONE]

COUNT(DIST  
----------  
        68  
1 row returned
> ; <TEST=CD3>
> ;16
> select count(distinct profession), '1' from prospects \
 (cont) >   where cr_limit > 0
[SELECT_ITEMS=
1,Expr,"COUNT(DISTINCT PROSPECTS.PROFESSION)",,UNS INT(4),,C STRING(11)
2,String,'1',,C STRING(2),,C STRING(2)]
[ORDER_BY=NONE]

COUNT(DIST  1  
----------  -  
         6  1  
1 row returned
> ; <TEST=CD4>
> ;17
> select division, dept, count(distinct cost) from products \
 (cont) >   group by division, dept
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.PRODUCTS.DIVISION,,TINYINT(1),,C STRING(6)
2,Column,STAR_ENV.STAR.PRODUCTS.DEPT,,SMALLINT(2),,C STRING(8)
3,Expr,"COUNT(DISTINCT PRODUCTS.COST)",,UNS INT(4),,C STRING(11)]
[ORDER_BY=NONE]

DIVIS  DEPT     COUNT(DIST  
-----  -------  ----------  
    1        1           9  
    1        2           9  
    2        3          10  
    2        4           4  
    3        5           8  
    3        6           5  
    4        7          13  
    4        8           2  
    5        9          14  
    5       10           5  
10 rows returned
> ; <TEST=CD5>
> ;18
> select count(distinct order_date) from orders \
 (cont) >   where order_date > '01-01-1996' or quantity between 1 and 5 \
 (cont) >         or sales_tax < 4.00 \
 (cont) >   group by acct
[SELECT_ITEMS=
1,Expr,"COUNT(DISTINCT ORDERS.ORDER_DATE)",,UNS INT(4),,C STRING(11)]
[ORDER_BY=NONE]

COUNT(DIST  
----------  
        64  
        18  
         1  
3 rows returned
> ; <TEST=CD6>
> ;19
> select count(distinct total) from orders \
 (cont) >   group by order_date, discount having count(distinct total) > 1
[SELECT_ITEMS=
1,Expr,"COUNT(DISTINCT ORDERS.TOTAL)",,UNS INT(4),,C STRING(11)]
[ORDER_BY=NONE]

COUNT(DIST  
----------  
         5  
         2  
         3  
         5  
         6  
         2  
         4  
         4  
         6  
         2  
         2  
         2  
         2  
         3  
         4  
         3  
         3  
         2  
         2  
         4  
         2  
         3  
         3  
         2  
         5  
         5  
         3  
         2  
         2  
         2  
         2  
         3  
         2  
         2  
         2  
         3  
         4  
         3  
         2  
         2  
         3  
         2  
         4  
         3  
         2  
         4  
         5  
         2  
         2  
         5  
         2  
         3  
         2  
         2  
         3  
         2  
56 rows returned
> ; Test reuse
> ; <TEST=CD6r>
> ;20
> select count(distinct total) from orders \
 (cont) >   group by order_date, discount having count(distinct total) > 1
[SELECT_ITEMS=
1,Expr,"COUNT(DISTINCT ORDERS.TOTAL)",,UNS INT(4),,C STRING(11)]
[ORDER_BY=NONE]

COUNT(DIST  
----------  
         5  
         2  
         3  
         5  
         6  
         2  
         4  
         4  
         6  
         2  
         2  
         2  
         2  
         3  
         4  
         3  
         3  
         2  
         2  
         4  
         2  
         3  
         3  
         2  
         5  
         5  
         3  
         2  
         2  
         2  
         2  
         3  
         2  
         2  
         2  
         3  
         4  
         3  
         2  
         2  
         3  
         2  
         4  
         3  
         2  
         4  
         5  
         2  
         2  
         5  
         2  
         3  
         2  
         2  
         3  
         2  
56 rows returned
> ; <TEST=CD7>
> ; permuted sort>
> ;21
> select every 5 discount, order_date, count(distinct total) from orders \
 (cont) >   where tax_state in ('CO', 'CA', 'AZ') and \
 (cont) >         (discount >= 10 or (quantity < 100 and amount > 100)) \
 (cont) >   group by discount, order_date having count(distinct total) > 1 \
 (cont) >   order by 1, 2, 3
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.ORDERS.DISCOUNT,,TINYINT(1),,C STRING(6)
2,Column,STAR_ENV.STAR.ORDERS.ORDER_DATE,,ODX DATE(4),YYYYMMDD,C STRING(17)
3,Expr,"COUNT(DISTINCT ORDERS.TOTAL)",,UNS INT(4),,C STRING(11)]
[ORDER_BY=1,2,3]

DISCO  ORDER_DATE        COUNT(DIST  
-----  ----------------  ----------  
   22      Jun 20, 1990           6  
   22      Jan 20, 1991           2  
   22      Jan 20, 1992           4  
   22      Oct 20, 1992           4  
   22      Sep 20, 1993           5  
   22      Feb 20, 1994           2  
   22      Jul 20, 1994           3  
   22      Feb 20, 1995           5  
   22      Aug 20, 1996           2  
9 rows returned
> ;
> ;
> ;Tests un-optimized count(distinct col)
> ;
> ; <TEST=CD8>
> ;22
> select count(distinct dt) from activity
[SELECT_ITEMS=
1,Expr,"COUNT(DISTINCT ACTIVITY.DT)",,UNS INT(4),,C STRING(11)]
[ORDER_BY=NONE]

COUNT(DIST  
----------  
        40  
1 row returned
> ; <TEST=CD9>
> ;23
> select count(distinct zip) from prospects \
 (cont) >   where cust_since <= 1992 and last_order >= '07-31-1998'
[SELECT_ITEMS=
1,Expr,"COUNT(DISTINCT PROSPECTS.ZIP)",,UNS INT(4),,C STRING(11)]
[ORDER_BY=NONE]

COUNT(DIST  
----------  
         1  
1 row returned
> ; <TEST=CD10>
> ; DB2 aborts
> ; <COMPARE='DBMS="NOT DB2"'>
> ;24
> select (1.0 / count(distinct acct)) * 100 from orders
[SELECT_ITEMS=
1,Expr,"1.0 / COUNT(DISTINCT ORDERS.ACCT) * 100",,DOUBLE(8),,C STRING(33)]
[ORDER_BY=NONE]

1.0 / COUNT(DISTINCT ORDERS.ACCT  
--------------------------------  
                       33.333333  
1 row returned
> ; <END_COMPARE>
> ;
> ;Multiple counts per statement
> ; <TEST=MC1>
> ;25
> select count(*), count(distinct acct), count(distinct discount_rt) from prospects
[SELECT_ITEMS=
1,Expr,"COUNT('*')",,UNS INT(4),,C STRING(11)
2,Expr,"COUNT(DISTINCT PROSPECTS.ACCT)",,UNS INT(4),,C STRING(11)
3,Expr,"COUNT(DISTINCT PROSPECTS.DISCOUNT_RT)",,UNS INT(4),,C STRING(11)]
[ORDER_BY=NONE]

COUNT('*')  COUNT(DIST  COUNT(DIST  
----------  ----------  ----------  
        10          10           4  
1 row returned
> ; <TEST=MC2>
> ;26
> select count(tax_state), count(distinct source) from orders
[SELECT_ITEMS=
1,Expr,"COUNT(ORDERS.TAX_STATE)",,UNS INT(4),,C STRING(11)
2,Expr,"COUNT(DISTINCT ORDERS.SOURCE)",,UNS INT(4),,C STRING(11)]
[ORDER_BY=NONE]

COUNT(ORDE  COUNT(DIST  
----------  ----------  
       200           6  
1 row returned
> ; <TEST=MC3>
> ;27
> select count(distinct o.acct), count(o.amount), count(distinct s.description) \
 (cont) >   from orders o join statuses s using (status) \
 (cont) >   where o.pmt_method <= 2 and o.total >= 2000.00 \
 (cont) >         and s.description = 'Shipped' and o.source = 6
[SELECT_ITEMS=
1,Expr,"COUNT(DISTINCT O.ACCT)",,UNS INT(4),,C STRING(11)
2,Expr,"COUNT(O.AMOUNT)",,UNS INT(4),,C STRING(11)
3,Expr,"COUNT(DISTINCT S.DESCRIPTION)",,UNS INT(4),,C STRING(11)]
[ORDER_BY=NONE]

COUNT(DIST  COUNT(O.AM  COUNT(DIST  
----------  ----------  ----------  
         2           4           1  
1 row returned
> ; <TEST=MC4>
> ;28
> select count(distinct status), count(*), count(distinct status), \
 (cont) >   sum(distinct discount) \
 (cont) >   from orders \
 (cont) >   where ((order_date between '01-01-1996' and '12-31-1996' \
 (cont) >   and quantity > 10) or \
 (cont) >   (order_date between '01-01-1995'and '12-31-1995' \
 (cont) >   and (quantity > 10 or total > 10000))) and tax_state like 'CO'
[SELECT_ITEMS=
1,Expr,"COUNT(DISTINCT ORDERS.STATUS)",,UNS INT(4),,C STRING(11)
2,Expr,"COUNT('*')",,UNS INT(4),,C STRING(11)
3,Expr,"COUNT(DISTINCT ORDERS.STATUS)",,UNS INT(4),,C STRING(11)
4,Expr,"SUM(DISTINCT ORDERS.DISCOUNT)",,DOUBLE(8),,C STRING(33)]
[ORDER_BY=NONE]

COUNT(DIST  COUNT('*')  COUNT(DIST  SUM(DISTINCT ORDERS.DISCOUNT)     
----------  ----------  ----------  --------------------------------  
         1           6           1                         22.000000  
1 row returned
> ; <TEST=MC5>
> ;29
> select count(f.description), count(distinct f.description), max(p.last_order), \
 (cont) >   count(s.description), min(distinct income) \
 (cont) >   from prospects p, professions f, states s, zipcodes z \
 (cont) >   where (p.profession = f.profession and p.state = s.state \
 (cont) >         and p.zip = z.zip) and \
 (cont) >         ((p.state in ('KS', 'WA', 'CA', 'NE', 'OR', 'CO', 'UT', 'IL') \
 (cont) >         and (s.region = 'MW' or s.region = 'SW')) or (p.cust_since > 1995 \
 (cont) >         and (((f.description = 'Legal' or f.description = 'Finance') \
 (cont) >         and income < 7) or \
 (cont) >         (f.description in ('Educator', 'Clerical/Administrative', 'Retired') \
 (cont) >         and income > 7))))
[SELECT_ITEMS=
1,Expr,"COUNT(F.DESCRIPTION)",,UNS INT(4),,C STRING(11)
2,Expr,"COUNT(DISTINCT F.DESCRIPTION)",,UNS INT(4),,C STRING(11)
3,Expr,"MAX(P.LAST_ORDER)",,ODX DATE(4),YYYYMMDD,C STRING(17)
4,Expr,"COUNT(S.DESCRIPTION)",,UNS INT(4),,C STRING(11)
5,Expr,"MIN(DISTINCT P.INCOME)",,TINYINT(1),,C STRING(6)]
[ORDER_BY=NONE]

COUNT(F.DE  COUNT(DIST  MAX(P.LAST_ORDER  COUNT(S.DE  MIN(D  
----------  ----------  ----------------  ----------  -----  
         7           6       Jan 3, 2002           7      1  
1 row returned
> ; <TEST=MC6>
> ;30
> select sum(total), avg(amount), count(1), min(quantity), avg(total), count(*) \
 (cont) >   from orders where discount != 0 \
 (cont) >   group by acct order by 4, 1 with ask_retrieval_threshold = 10
[SELECT_ITEMS=
1,Expr,"SUM(ORDERS.TOTAL)",,DOUBLE(8),,C STRING(33)
2,Expr,"AVG(ORDERS.AMOUNT)",,DOUBLE(8),,C STRING(33)
3,Expr,"COUNT(1)",,UNS INT(4),,C STRING(11)
4,Expr,"MIN(ORDERS.QUANTITY)",,TINYINT(1),,C STRING(6)
5,Expr,"AVG(ORDERS.TOTAL)",,DOUBLE(8),,C STRING(33)
6,Expr,"COUNT('*')",,UNS INT(4),,C STRING(11)]
[ORDER_BY=4,1]

SUM(ORDERS.TOTAL)                 AVG(ORDERS.AMOUNT)                
--------------------------------  --------------------------------  
COUNT(1)    MIN(O  AVG(ORDERS.TOTAL)                 COUNT('*')  
----------  -----  --------------------------------  ----------  
                   161371.800000                        696.100000  
        36      1                       4482.550000          36  
                   426175.619165                        677.432394  
       163      1                       2614.574351         163  
2 rows returned
> ; <TEST=MC7>
> ;31
> select count(distinct margin), count(distinct cost) from products \
 (cont) >   where category > 10
[SELECT_ITEMS=
1,Expr,"COUNT(DISTINCT PRODUCTS.MARGIN)",,UNS INT(4),,C STRING(11)
2,Expr,"COUNT(DISTINCT PRODUCTS.COST)",,UNS INT(4),,C STRING(11)]
[ORDER_BY=NONE]

COUNT(DIST  COUNT(DIST  
----------  ----------  
         4          57  
1 row returned
> ; <TEST=MC8>
> ;32
> select count(distinct profession), count(distinct cust_since), \
 (cont) >        count(distinct last_order) from prospects
[SELECT_ITEMS=
1,Expr,"COUNT(DISTINCT PROSPECTS.PROFESSION)",,UNS INT(4),,C STRING(11)
2,Expr,"COUNT(DISTINCT PROSPECTS.CUST_SINCE)",,UNS INT(4),,C STRING(11)
3,Expr,"COUNT(DISTINCT PROSPECTS.LAST_ORDER)",,UNS INT(4),,C STRING(11)]
[ORDER_BY=NONE]

COUNT(DIST  COUNT(DIST  COUNT(DIST  
----------  ----------  ----------  
         9           6          10  
1 row returned
> ; <TEST=MC9>
> ;33
> select count(distinct quantity), count(distinct sales_tax), \
 (cont) >   count(distinct amount), count(distinct acct) from orders
[SELECT_ITEMS=
1,Expr,"COUNT(DISTINCT ORDERS.QUANTITY)",,UNS INT(4),,C STRING(11)
2,Expr,"COUNT(DISTINCT ORDERS.SALES_TAX)",,UNS INT(4),,C STRING(11)
3,Expr,"COUNT(DISTINCT ORDERS.AMOUNT)",,UNS INT(4),,C STRING(11)
4,Expr,"COUNT(DISTINCT ORDERS.ACCT)",,UNS INT(4),,C STRING(11)]
[ORDER_BY=NONE]

COUNT(DIST  COUNT(DIST  COUNT(DIST  COUNT(DIST  
----------  ----------  ----------  ----------  
        20         111          64           3  
1 row returned
> ; <TEST=MC10>
> ;34
> select count(distinct total), count(distinct product_no), count(distinct quantity), \
 (cont) >   count(distinct order_date) from orders \
 (cont) >   where tax_state in ('CO', 'CA', 'AZ') and \
 (cont) >         (discount >= 10 or (quantity < 100 and amount > 100)) \
 (cont) >   group by acct
[SELECT_ITEMS=
1,Expr,"COUNT(DISTINCT ORDERS.TOTAL)",,UNS INT(4),,C STRING(11)
2,Expr,"COUNT(DISTINCT ORDERS.PRODUCT_NO)",,UNS INT(4),,C STRING(11)
3,Expr,"COUNT(DISTINCT ORDERS.QUANTITY)",,UNS INT(4),,C STRING(11)
4,Expr,"COUNT(DISTINCT ORDERS.ORDER_DATE)",,UNS INT(4),,C STRING(11)]
[ORDER_BY=NONE]

COUNT(DIST  COUNT(DIST  COUNT(DIST  COUNT(DIST  
----------  ----------  ----------  ----------  
        84          55          19          65  
1 row returned
> ;
> ;
> ; <SECTION=KEYWD_OPTIMIZATION>
> ;
> ;Tests use of KEYWD option (dist ;np col; group by col; count() group by col)
> ; order by is supported ONLY if the order column is the select column
> ;
> ; KEYWD
> ; <TEST=K1>
> ;  NP c string>
> ;35
> select distinct zip from prospects
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.PROSPECTS.ZIP,,C STRING(10),,C STRING(10)]
[ORDER_BY=NONE]

ZIP        
---------  
11375      
48072      
53151      
62301      
68114      
77098      
80301      
85269      
90505      
90710      
10 rows returned
> ; <TEST=K2>
> ; odx date
> ;36
> select top 25% distinct dt from activity
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.ACTIVITY.DT,,ODX DATE(4),YYYYMMDD,C STRING(17)]
[ORDER_BY=NONE]

DT                
----------------  
     Feb 1, 1990  
     May 1, 1990  
     Jul 1, 1990  
     Nov 1, 1990  
     Feb 1, 1991  
     May 1, 1991  
     Jul 1, 1991  
     Nov 1, 1991  
     Feb 1, 1992  
     May 1, 1992  
10 rows returned
> ; Test reuse
> ; <TEST=K2r>
> ;37
> select top 25% distinct dt from activity
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.ACTIVITY.DT,,ODX DATE(4),YYYYMMDD,C STRING(17)]
[ORDER_BY=NONE]

DT                
----------------  
     Feb 1, 1990  
     May 1, 1990  
     Jul 1, 1990  
     Nov 1, 1990  
     Feb 1, 1991  
     May 1, 1991  
     Jul 1, 1991  
     Nov 1, 1991  
     Feb 1, 1992  
     May 1, 1992  
10 rows returned
> ; <TEST=K3>
> ;  int 1
> ;38
> select distinct category from products order by category
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.PRODUCTS.CATEGORY,,INT(4),,C STRING(12)]
[ORDER_BY=1]

CATEGORY     
-----------  
11           
12           
13           
21           
22           
23           
31           
41           
42           
43           
51           
52           
53           
61           
62           
71           
72           
73           
74           
75           
81           
91           
92           
93           
94           
95           
101          
102          
103          
104          
30 rows returned
> ; KWCOUNT
> ; <TEST=K4>
> ;  float
> ;39
> select count(*) from orders group by sales_tax
[SELECT_ITEMS=
1,Expr,"COUNT('*')",,UNS INT(4),,C STRING(11)]
[ORDER_BY=NONE]

COUNT('*')  
----------  
         4  
         1  
         2  
         1  
         1  
         1  
         2  
         3  
         1  
         1  
         1  
         1  
         1  
         3  
         1  
         2  
         1  
         2  
         1  
         1  
         1  
         2  
         1  
         6  
         1  
         1  
         1  
         1  
         5  
         1  
         2  
         8  
         2  
         1  
         1  
         2  
         3  
         1  
         1  
         1  
         8  
         1  
         5  
         1  
         3  
         5  
         1  
         1  
         2  
         1  
         1  
         1  
         1  
         4  
         1  
         1  
         2  
         1  
         2  
         1  
         2  
         4  
         1  
         1  
         8  
         3  
         2  
         5  
         3  
         6  
         2  
         2  
         1  
         1  
         3  
         2  
         1  
         1  
         1  
         1  
         1  
         1  
         1  
         1  
         3  
         1  
         1  
         2  
         1  
         1  
         1  
         1  
         1  
         1  
         1  
         1  
         1  
         1  
         1  
         1  
         1  
         1  
         1  
         1  
         1  
         1  
         1  
         1  
         1  
         1  
         1  
111 rows returned
> ; <TEST=K5>
> ;
> ;40
> select category, count(*) from products group by category
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.PRODUCTS.CATEGORY,,INT(4),,C STRING(12)
2,Expr,"COUNT('*')",,UNS INT(4),,C STRING(11)]
[ORDER_BY=NONE]

CATEGORY     COUNT('*')  
-----------  ----------  
11                    4  
12                    4  
13                    2  
21                    4  
22                    1  
23                    4  
31                   11  
41                    1  
42                    2  
43                    2  
51                    1  
52                    4  
53                    5  
61                    3  
62                    2  
71                    3  
72                    2  
73                    3  
74                    2  
75                    9  
81                    4  
91                    2  
92                    5  
93                    9  
94                    2  
95                    1  
101                   2  
102                   2  
103                   2  
104                   2  
30 rows returned
> ; KWPCOUNT
> ; <TEST=K6>
> ;  int 4 si
> ;41
> select count(distinct acct) from orders group by source
[SELECT_ITEMS=
1,Expr,"COUNT(DISTINCT ORDERS.ACCT)",,UNS INT(4),,C STRING(11)]
[ORDER_BY=NONE]

COUNT(DIST  
----------  
         2  
         2  
         2  
         2  
         2  
         3  
6 rows returned
> ; <TEST=K7>
> ;  odx date si
> ;42
> select quantity, count(order_date), count(distinct order_date) from orders \
 (cont) >  group by quantity
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.ORDERS.QUANTITY,,TINYINT(1),,C STRING(6)
2,Expr,"COUNT(ORDERS.ORDER_DATE)",,UNS INT(4),,C STRING(11)
3,Expr,"COUNT(DISTINCT ORDERS.ORDER_DATE)",,UNS INT(4),,C STRING(11)]
[ORDER_BY=NONE]

QUANT  COUNT(ORDE  COUNT(DIST  
-----  ----------  ----------  
    1         144          65  
    2           2           2  
    3           3           3  
    4           3           3  
    5           2           2  
    6           4           4  
    7           3           3  
    8           2           2  
    9           2           2  
   10           3           3  
   11           3           3  
   12           4           4  
   13           6           6  
   14           2           2  
   15           2           2  
   16           2           2  
   17           1           1  
   18           6           6  
   19           5           5  
   20           1           1  
20 rows returned
> ; Test reuse
> ; <TEST=K7r>
> ;43
> select quantity, count(order_date), count(distinct order_date) from orders \
 (cont) >  group by quantity
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.ORDERS.QUANTITY,,TINYINT(1),,C STRING(6)
2,Expr,"COUNT(ORDERS.ORDER_DATE)",,UNS INT(4),,C STRING(11)
3,Expr,"COUNT(DISTINCT ORDERS.ORDER_DATE)",,UNS INT(4),,C STRING(11)]
[ORDER_BY=NONE]

QUANT  COUNT(ORDE  COUNT(DIST  
-----  ----------  ----------  
    1         144          65  
    2           2           2  
    3           3           3  
    4           3           3  
    5           2           2  
    6           4           4  
    7           3           3  
    8           2           2  
    9           2           2  
   10           3           3  
   11           3           3  
   12           4           4  
   13           6           6  
   14           2           2  
   15           2           2  
   16           2           2  
   17           1           1  
   18           6           6  
   19           5           5  
   20           1           1  
20 rows returned
> ;Make sure we don't try on non-NP colums
> ; <TEST=K8>
> ;44
> select distinct city from prospects
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.PROSPECTS.CITY,,C STRING(26),,C STRING(26)]
[ORDER_BY=NONE]

CITY                       
-------------------------  
Berkley                    
Boulder                    
Flushing                   
Fountain Hills             
Harbor City                
Houston                    
New Berlin                 
Omaha                      
Quincy                     
Torrance                   
10 rows returned
> ; <TEST=K9>
> ;45
> select city, count(*) from prospects group by city
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.PROSPECTS.CITY,,C STRING(26),,C STRING(26)
2,Expr,"COUNT('*')",,UNS INT(4),,C STRING(11)]
[ORDER_BY=NONE]

CITY                       COUNT('*')  
-------------------------  ----------  
Berkley                             1  
Boulder                             1  
Flushing                            1  
Fountain Hills                      1  
Harbor City                         1  
Houston                             1  
New Berlin                          1  
Omaha                               1  
Quincy                              1  
Torrance                            1  
10 rows returned
> ; <TEST=K10>
> ;46
> select tax_state, count(distinct acct) from orders group by tax_state
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.ORDERS.TAX_STATE,,CHAR(2),,CHAR(2)
2,Expr,"COUNT(DISTINCT ORDERS.ACCT)",,UNS INT(4),,C STRING(11)]
[ORDER_BY=NONE]

TA  COUNT(DIST  
--  ----------  
CO           1  
IL           1  
TX           1  
3 rows returned
> ;
> ;
> ; <SECTION=DISTINCT(COL-LIST)>
> ;
> ;Tests optimized "distinct imsam-col(s) order by imsam-col(s)"
> ; uses agg index; only works if all the select items are order items
> ; and order by is same order as components
> ;
> ; <TEST=DO1>
> ;47
> select distinct profession, income from prospects order by 1, 2
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.PROSPECTS.PROFESSION,,TINYINT(1),,C STRING(6)
2,Column,STAR_ENV.STAR.PROSPECTS.INCOME,,TINYINT(1),,C STRING(6)]
[ORDER_BY=1,2]

PROFE  INCOM  
-----  -----  
    1     16  
    2     11  
    3      7  
    4      5  
    6      5  
    7      8  
    8      1  
    9      5  
    9      8  
   10      1  
10 rows returned
> ; <TEST=DO2>
> ;48
> select top 10 distinct total, status from orders order by 2, 1
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.ORDERS.TOTAL,,FLOAT(4),,C STRING(33)
2,Column,STAR_ENV.STAR.ORDERS.STATUS,,CHAR(2),,CHAR(2)]
[ORDER_BY=2,1]

TOTAL                             ST  
--------------------------------  --  
                        7.020000  CN  
                       70.199997  CN  
                       93.599998  CN  
                      249.600006  CN  
                      842.399963  CN  
                     1638.000000  CN  
                     1755.000000  CN  
                     1829.880005  CN  
                        0.780000  SH  
                        0.900000  SH  
10 rows returned
> ; Test reuse
> ; <TEST=DO2r>
> ;49
> select top 10 distinct total, status from orders order by 2, 1
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.ORDERS.TOTAL,,FLOAT(4),,C STRING(33)
2,Column,STAR_ENV.STAR.ORDERS.STATUS,,CHAR(2),,CHAR(2)]
[ORDER_BY=2,1]

TOTAL                             ST  
--------------------------------  --  
                        7.020000  CN  
                       70.199997  CN  
                       93.599998  CN  
                      249.600006  CN  
                      842.399963  CN  
                     1638.000000  CN  
                     1755.000000  CN  
                     1829.880005  CN  
                        0.780000  SH  
                        0.900000  SH  
10 rows returned
> ; <TEST=DO3>
> ;50
> select distinct order_date, discount, quantity, total from orders \
 (cont) >  order by 1,2,3,4
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.ORDERS.ORDER_DATE,,ODX DATE(4),YYYYMMDD,C STRING(17)
2,Column,STAR_ENV.STAR.ORDERS.DISCOUNT,,TINYINT(1),,C STRING(6)
3,Column,STAR_ENV.STAR.ORDERS.QUANTITY,,TINYINT(1),,C STRING(6)
4,Column,STAR_ENV.STAR.ORDERS.TOTAL,,FLOAT(4),,C STRING(33)]
[ORDER_BY=1,2,3,4]

ORDER_DATE        DISCO  QUANT  TOTAL                             
----------------  -----  -----  --------------------------------  
    Jan 20, 1990     22      1                          1.560000  
    Jan 20, 1990     22      1                         65.519997  
    Jan 20, 1990     22      1                        195.000000  
    Jan 20, 1990     22      1                        390.000000  
    Jan 20, 1990     22     18                         42.119999  
    Feb 20, 1990     22      1                       1833.000000  
    Mar 20, 1990     22      1                        358.799988  
    Mar 20, 1990     22     14                        316.680023  
    Apr 20, 1990     22      1                          7.020000  
    Apr 20, 1990     22      1                       1829.880005  
    Apr 20, 1990     22      7                      12831.000000  
    May 20, 1990     22      1                        152.100006  
    May 20, 1990     22      1                        156.000000  
    May 20, 1990     22      1                        195.000000  
    May 20, 1990     22      1                       1857.180054  
    May 20, 1990     22     18                       5616.000000  
    Jun 20, 1990     22      1                        312.000000  
    Jun 20, 1990     22      1                        390.000000  
    Jun 20, 1990     22      1                       1700.400024  
    Jun 20, 1990     22      1                       1833.000000  
    Jun 20, 1990     22      1                       2168.399902  
    Jun 20, 1990     22     17                       2254.200195  
    Aug 20, 1990     22      1                         78.000000  
    Aug 20, 1990     22      9                        702.000000  
    Oct 20, 1990     22      1                         70.199997  
    Oct 20, 1990     22      1                         93.599998  
    Oct 20, 1990     22      5                        113.100006  
    Oct 20, 1990     22      7                        273.000000  
    Nov 20, 1990     22      1                          7.020000  
    Nov 20, 1990     22      1                        249.600006  
    Nov 20, 1990     22      3                       5571.540039  
    Nov 20, 1990     22     19                        741.000000  
    Dec 20, 1990     22      1                        132.600006  
    Dec 20, 1990     22      1                        156.000000  
    Dec 20, 1990     22      1                        163.800003  
    Dec 20, 1990     22      1                       1857.180054  
    Dec 20, 1990     22     11                      18018.000000  
    Dec 20, 1990     22     14                      30357.597656  
    Jan 20, 1991     22      1                       1904.760010  
    Jan 20, 1991     22     18                      16146.000000  
    Feb 20, 1991     22      1                       1700.400024  
    Mar 20, 1991     22      1                         39.000000  
    Mar 20, 1991     22      1                        132.600006  
    Jun 20, 1991     22      1                        312.000000  
    Jun 20, 1991     22      1                       1638.000000  
    Jul 20, 1991     22      1                        312.000000  
    Jul 20, 1991     22      3                       5101.200195  
    Aug 20, 1991     22      1                       1829.880005  
    Sep 20, 1991     22      1                       1829.880005  
    Nov 20, 1991     22      1                       1904.760010  
    Dec 20, 1991     22      1                         27.299999  
    Dec 20, 1991     22      1                       1755.000000  
    Dec 20, 1991     22      1                       2067.000000  
    Jan 20, 1992     22      1                          0.780000  
    Jan 20, 1992     22      1                        358.799988  
    Jan 20, 1992     22      1                       1700.400024  
    Jan 20, 1992     22     13                       4056.000000  
    Feb 20, 1992     22      1                       1638.000000  
    Feb 20, 1992     22     12                      19656.000000  
    Feb 20, 1992     22     13                       2028.000000  
    Mar 20, 1992     22      1                         22.620001  
    Mar 20, 1992     22      1                         70.199997  
    Mar 20, 1992     22     20                       6240.000000  
    Jun 20, 1992     22      1                         39.000000  
    Jun 20, 1992     22     13                      23788.439453  
    Aug 20, 1992     22      1                        132.600006  
    Aug 20, 1992     22      1                        152.100006  
    Oct 20, 1992     22      1                        312.000000  
    Oct 20, 1992     22      1                       1857.180054  
    Oct 20, 1992     22      1                       1872.000000  
    Oct 20, 1992     22     10                      21684.000000  
    Dec 20, 1992     22      1                        156.000000  
    Dec 20, 1992     22      4                        530.400024  
    Jan 20, 1993     22      1                        132.600006  
    Jan 20, 1993     22      1                       1638.000000  
    Jan 20, 1993     22      1                       1857.180054  
    Feb 20, 1993     22      1                          5.460000  
    Apr 20, 1993     22      1                       1829.880005  
    Apr 20, 1993     22      1                       2067.000000  
    Apr 20, 1993     22     15                       2281.500000  
    May 20, 1993     22      1                         22.620001  
    Jun 20, 1993     22      3                        468.000000  
    Aug 20, 1993     22      1                          2.340000  
    Aug 20, 1993     22      4                        624.000000  
    Sep 20, 1993     22      1                          0.780000  
    Sep 20, 1993     22      1                        390.000000  
    Sep 20, 1993     22      8                       4929.600098  
    Sep 20, 1993     22      9                        631.799988  
    Sep 20, 1993     22     11                      20128.679688  
    Oct 20, 1993     22      1                         24.959999  
    Oct 20, 1993     22      1                        358.799988  
    Oct 20, 1993     22      1                        897.000000  
    Oct 20, 1993     22      1                       1638.000000  
    Oct 20, 1993     22     10                        702.000000  
    Nov 20, 1993     22      1                        234.000000  
    Nov 20, 1993     22      1                        312.000000  
    Nov 20, 1993     22     19                      33345.000000  
    Dec 20, 1993     22      1                         65.519997  
    Dec 20, 1993     22      1                        156.000000  
    Jan 20, 1994     10      6                       2160.000000  
    Jan 20, 1994     10     13                      28080.000000  
    Jan 20, 1994     22      1                          7.020000  
    Jan 20, 1994     22      1                        358.799988  
    Feb 20, 1994     10      1                       2160.000000  
    Feb 20, 1994     22      1                        163.800003  
    Feb 20, 1994     22      6                       5382.000000  
    Mar 20, 1994     10      1                          5.400000  
    Mar 20, 1994     10      1                        175.500000  
    Mar 20, 1994     10      1                        360.000000  
    Mar 20, 1994     22      6                        421.199982  
    Mar 20, 1994     22     12                        842.399963  
    Apr 20, 1994     10      1                         31.500000  
    Apr 20, 1994     22      1                         70.199997  
    Apr 20, 1994     22     15                       2340.000000  
    May 20, 1994     10      6                      12690.000000  
    May 20, 1994     22      1                         22.620001  
    May 20, 1994     22      1                        616.200012  
    Jun 20, 1994     22      1                       1638.000000  
    Jun 20, 1994     22     11                       2574.000000  
    Jun 20, 1994     22     19                       3705.000000  
    Jul 20, 1994     10      1                        207.000000  
    Jul 20, 1994     10      1                       1890.000000  
    Jul 20, 1994     10      1                       2025.000000  
    Jul 20, 1994     10      8                        360.000000  
    Jul 20, 1994     22      1                        897.000000  
    Jul 20, 1994     22      1                       1857.180054  
    Jul 20, 1994     22     19                      36190.441406  
    Aug 20, 1994     10      1                        450.000000  
    Aug 20, 1994     10      4                        720.000000  
    Aug 20, 1994     22      2                        312.000000  
    Sep 20, 1994     10      1                        450.000000  
    Sep 20, 1994     10     16                      34560.000000  
    Sep 20, 1994     22      1                        234.000000  
    Sep 20, 1994     22      1                        390.000000  
    Sep 20, 1994     22      1                        616.200012  
    Oct 20, 1994     10      1                         90.000000  
    Oct 20, 1994     10     12                        972.000000  
    Oct 20, 1994     22      1                        312.000000  
    Oct 20, 1994     22      1                        616.200012  
    Oct 20, 1994     22      1                       1638.000000  
    Oct 20, 1994     22      1                       1857.180054  
    Nov 20, 1994     10      1                        180.000000  
    Nov 20, 1994     22      1                         42.900002  
    Nov 20, 1994     22      1                        179.399994  
    Nov 20, 1994     22      1                       1872.000000  
    Dec 20, 1994     22      1                          3.120000  
    Jan 20, 1995     10      1                          8.100000  
    Jan 20, 1995     10      1                       1890.000000  
    Jan 20, 1995     22      1                         62.400002  
    Jan 20, 1995     22      1                         70.199997  
    Jan 20, 1995     22      1                       1829.880005  
    Jan 20, 1995     22      7                       1092.000000  
     Feb 8, 1995      0      1                          6.000000  
    Feb 20, 1995     22      1                        132.600006  
    Feb 20, 1995     22      1                        312.000000  
    Feb 20, 1995     22      1                       1755.000000  
    Feb 20, 1995     22     12                          9.360000  
    Feb 20, 1995     22     18                       3510.000000  
    Mar 20, 1995     10      1                          0.900000  
    Mar 20, 1995     22      1                        156.000000  
    Mar 20, 1995     22     13                       3244.800049  
    Apr 20, 1995     10      1                        180.000000  
    May 20, 1995     10     16                      33840.000000  
    May 20, 1995     22      1                          0.780000  
    Jun 20, 1995     10      1                          0.900000  
    Jun 20, 1995     10      1                        450.000000  
    Jun 20, 1995     22      1                        156.000000  
    Jul 20, 1995     10      1                          4.500000  
    Jul 20, 1995     22      1                          4.680000  
    Jul 20, 1995     22      1                        140.399994  
    Jul 20, 1995     22      1                        616.200012  
    Jul 20, 1995     22      1                       2168.399902  
    Jul 20, 1995     22      5                         85.800003  
    Aug 20, 1995     10      1                        144.000000  
    Aug 20, 1995     10      1                        225.000000  
    Aug 20, 1995     22      1                         70.199997  
    Aug 20, 1995     22     13                      11661.000000  
    Aug 20, 1995     22     18                       2948.400146  
    Sep 20, 1995     10      1                       1890.000000  
    Sep 20, 1995     10     18                      34020.000000  
    Sep 20, 1995     22      1                       2067.000000  
    Oct 20, 1995     10      1                        234.000000  
    Oct 20, 1995     22      1                          5.460000  
    Nov 20, 1995     10      1                        270.000000  
    Nov 20, 1995     10     10                         18.000000  
    Nov 20, 1995     22      1                       1638.000000  
    Dec 20, 1995     22      1                          0.780000  
    Dec 20, 1995     22      1                         27.299999  
    Dec 20, 1995     22      1                       1638.000000  
    Feb 20, 1996     22     19                      31122.000000  
    Apr 20, 1996     22      1                       1833.000000  
    May 20, 1996     22      2                        468.000000  
    Jun 23, 1996     10      1                        450.000000  
    Aug 20, 1996     22      1                         70.199997  
    Aug 20, 1996     22      1                        390.000000  
    Sep 20, 1996     22      1                        156.000000  
     Jan 3, 2002     22      1                        234.000000  
197 rows returned
> ;
> ;Tests distinct col-list (un-optimized)
> ;
> ; <TEST=DC1>
> ;51
> select distinct * from prospects
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.PROSPECTS.ACCT,,INT(4),,C STRING(12)
2,Column,STAR_ENV.STAR.PROSPECTS.COMPANY_ID,,INT(4),,C STRING(12)
3,Column,STAR_ENV.STAR.PROSPECTS.COMPANY,,C STRING(60),,C STRING(60)
4,Column,STAR_ENV.STAR.PROSPECTS.CONTACT,,C STRING(24),,C STRING(24)
5,Column,STAR_ENV.STAR.PROSPECTS.CITY,,C STRING(26),,C STRING(26)
6,Column,STAR_ENV.STAR.PROSPECTS.STATE,,CHAR(2),,CHAR(2)
7,Column,STAR_ENV.STAR.PROSPECTS.ZIP,,C STRING(10),,C STRING(10)
8,Column,STAR_ENV.STAR.PROSPECTS.REGION,,CHAR(2),,CHAR(2)
9,Column,STAR_ENV.STAR.PROSPECTS.COUNTRY,,CHAR(2),,CHAR(2)
10,Column,STAR_ENV.STAR.PROSPECTS.PHONE,,C STRING(16),,C STRING(16)
11,Column,STAR_ENV.STAR.PROSPECTS.GENDER,,CHAR(1),,CHAR(1)
12,Column,STAR_ENV.STAR.PROSPECTS.MAILFLAG,,CHAR(1),,CHAR(1)
13,Column,STAR_ENV.STAR.PROSPECTS.MAILING,,CHAR(1),,CHAR(1)
14,Column,STAR_ENV.STAR.PROSPECTS.PROFESSION,,TINYINT(1),,C STRING(6)
15,Column,STAR_ENV.STAR.PROSPECTS.INCOME,,TINYINT(1),,C STRING(6)
16,Column,STAR_ENV.STAR.PROSPECTS.PROFILE,,CHAR(1),,CHAR(1)
17,Column,STAR_ENV.STAR.PROSPECTS.PREFERRED,,CHAR(1),,CHAR(1)
18,Column,STAR_ENV.STAR.PROSPECTS.FRQ_BUY_MBR,,CHAR(1),,CHAR(1)
19,Column,STAR_ENV.STAR.PROSPECTS.CR_LIMIT,,TINYINT(1),,C STRING(6)
20,Column,STAR_ENV.STAR.PROSPECTS.DISCOUNT_RT,,TINYINT(1),,C STRING(6)
21,Column,STAR_ENV.STAR.PROSPECTS.CUST_SINCE,,ODX DATE(2),YYYY,C STRING(11)
22,Column,STAR_ENV.STAR.PROSPECTS.LAST_ORDER,,ODX DATE(4),YYYYMMDD,C STRING(17)
23,Column,STAR_ENV.STAR.PROSPECTS.SEARCH_KEY,,CHAR(12),,CHAR(12)
24,Pseudo,STAR_ENV.STAR.PROSPECTS.COMPANY_SDX,,C STRING(25),,C STRING(25)]
[ORDER_BY=NONE]

ACCT         COMPANY_ID   
-----------  -----------  
COMPANY                                                      
-----------------------------------------------------------  
CONTACT                  CITY                       ST  ZIP        RE  CO  
-----------------------  -------------------------  --  ---------  --  --  
PHONE            G  M  M  PROFE  INCOM  P  P  F  CR_LI  DISCO  CUST_SINCE  
---------------  -  -  -  -----  -----  -  -  -  -----  -----  ----------  
LAST_ORDER        SEARCH_KEY    COMPANY_SDX               
----------------  ------------  ------------------------  
          1         9234  
Dynamic Information Systems Corporation                      
Mark Trasko              Boulder                    CO  80301      SW  US  
3034444000       M  1  1      1     16  5  1  1      0     22        1990  
     Jan 3, 2002  TRAM8030190   DNMKNFRMTNSSTMSKRPRTN     
          2        25556  
Sanus/New York Life Health Plan                              
Joanne Meyer             Houston                    TX  77098      MW  US  
                 F  2  1      3      7  5  0  1     25     10        1994  
    Jun 23, 1996  MEYJ7709894   SNSNRKLFHLTPLN            
          3        12305  
GlenAir  Corporation                                         
Marty Kincaid            Quincy                     IL  62301      MW  US  
2172238567       M  1  1      4      5  5  0  0     15      0        1995  
     Feb 8, 1995  KINM6230195   GLNRKRPRTN                
          4         8289  
Data Dimensions                                              
Victor Warfield          Harbor City                CA  90710      SW  US  
3105399526       M  1  1      9      5  3  0  0     15      0        1996  
     Mar 7, 1997  WARV9071096   DTDMNSNS                  
          5        17875  
Maenner Relocation                                           
Harriet Gradziel         Omaha                      NE  68114      MW  US  
4023309606       F  1  1      8      1  3  0  1      0     12        1997  
    Mar 18, 1997  GRAH6811497   MNRRLKTN                  
          6        11487  
Frankulin Tool & Mfg. Company, Inc.                          
Clint Dion               New Berlin                 WI  53151      MW  US  
4147824521       M  1  1      9      8  3  0  0     30      0        1997  
     Mar 2, 1998  DIOC5315197   FRNKLNTLMFGKMPNNK         
          7        27512  
Strategic Systems Group                                      
Roxanne Dunagan          Torrance                   CA  90505      SW  US  
3105394111       F  2  1     10      1  2  0  0      0      0        1998  
     Aug 5, 1998  DUNR9050598   STRTGKSSTMSGRP            
          8        18652  
Medtronic Cardiocare                                         
Jack Niehause            Flushing                   NY  11375      NE  US  
                 M  1  1      6      5  3  0  0     15      0        1998  
     Oct 2, 1998  NIEJ1137598   MTRNKKRDKR                
          9        23377  
Productive Systems                                           
Michelle Behrman         Berkley                    MI  48072      MW  US  
4155407551       F  1  1      2     11  4  0  1     45     10        1998  
    May 13, 1998  BEHM4807298   PRDKTFSSTMS               
         10        26493  
Smith Information Management Systems                         
Anna Fireball            Fountain Hills             AZ  85269      SW  US  
6028376623       F  1  1      7      8  2  0  0     30      0        1998  
     Sep 8, 1998  FIRA8526998   SMTNFRMTNMNGMNTSSTMS      
10 rows returned
> ; <TEST=DC2>
> ;52
> select distinct discount_rt from prospects
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.PROSPECTS.DISCOUNT_RT,,TINYINT(1),,C STRING(6)]
[ORDER_BY=NONE]

DISCO  
-----  
0      
10     
12     
22     
4 rows returned
> ; Test reuse
> ; <TEST=DC2r>
> ;53
> select distinct discount_rt from prospects
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.PROSPECTS.DISCOUNT_RT,,TINYINT(1),,C STRING(6)]
[ORDER_BY=NONE]

DISCO  
-----  
0      
10     
12     
22     
4 rows returned
> ; <TEST=DC3>
> ;54
> select distinct tickler, 0, initials from activity \
 (cont) >  where initials = 'EFR' or tickler in ('MF', 'PC', 'RC')
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.ACTIVITY.TICKLER,,CHAR(2),,CHAR(2)
2,Number,0,,INT(4),,C STRING(12)
3,Column,STAR_ENV.STAR.ACTIVITY.INITIALS,,CHAR(4),,CHAR(4)]
[ORDER_BY=NONE]

TI  0            INIT  
--  -----------  ----  
MF            0  SHIP  
PC            0  EFR   
RC            0  JJK   
RC            0  TJK   
4 rows returned
> ; <TEST=DC4>
> ;55
> select distinct division, dept from products \
 (cont) >  where margin > 30 \
 (cont) >  order by 2,1
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.PRODUCTS.DIVISION,,TINYINT(1),,C STRING(6)
2,Column,STAR_ENV.STAR.PRODUCTS.DEPT,,SMALLINT(2),,C STRING(8)]
[ORDER_BY=2,1]

DIVIS  DEPT     
-----  -------  
    1        1  
    1        2  
    2        3  
    2        4  
    3        5  
    3        6  
    5        9  
7 rows returned
> ; expressions
> ; <TEST=DE1>
> ;56
> select distinct cost * 100 from products
[SELECT_ITEMS=
1,Expr,"PRODUCTS.COST * 100",,DOUBLE(8),,C STRING(33)]
[ORDER_BY=NONE]

PRODUCTS.COST * 100               
--------------------------------  
                      100.000000  
                      200.000000  
                      300.000000  
                      400.000000  
                      500.000000  
                      600.000000  
                      700.000000  
                      800.000000  
                      900.000000  
                     1100.000000  
                     1300.000000  
                     1500.000000  
                     2000.000000  
                     2200.000000  
                     2300.000000  
                     2600.000000  
                     2900.000000  
                     3000.000000  
                     3200.000000  
                     3500.000000  
                     4500.000000  
                     5000.000000  
                     5500.000000  
                     8000.000000  
                     8400.000000  
                     9000.000000  
                    10000.000000  
                    12000.000000  
                    16000.000000  
                    17000.000000  
                    18000.000000  
                    19500.000000  
                    20000.000000  
                    21000.000000  
                    23000.000000  
                    25000.000000  
                    26000.000000  
                    30000.000000  
                    32000.000000  
                    36000.000000  
                    40000.000000  
                    45000.000000  
                    46000.000000  
                    50000.000000  
                    70000.000000  
                    79000.000000  
                   115000.000000  
                   210000.000000  
                   218000.000000  
                   225000.000000  
                   234600.000000  
                   235000.000000  
                   238100.000000  
                   240000.000000  
                   244200.000000  
                   265000.000000  
                   278000.000000  
57 rows returned
> ; <TEST=DE2>
> ;57
> select distinct discount / 100.0 from orders \
 (cont) >  where (tax_state in ('CO', 'CA', 'AZ') and \
 (cont) >        discount >= 10) or (quantity < 100 and amount > 100)
[SELECT_ITEMS=
1,Expr,"ORDERS.DISCOUNT / 100.0",,DOUBLE(8),,C STRING(33)]
[ORDER_BY=NONE]

ORDERS.DISCOUNT / 100.0           
--------------------------------  
                        0.100000  
                        0.220000  
2 rows returned
> ; Test reuse
> ; <TEST=DE2r>
> ;58
> select distinct discount / 100.0 from orders \
 (cont) >  where (tax_state in ('CO', 'CA', 'AZ') and \
 (cont) >        discount >= 10) or (quantity < 100 and amount > 100)
[SELECT_ITEMS=
1,Expr,"ORDERS.DISCOUNT / 100.0",,DOUBLE(8),,C STRING(33)]
[ORDER_BY=NONE]

ORDERS.DISCOUNT / 100.0           
--------------------------------  
                        0.100000  
                        0.220000  
2 rows returned
> ; outside the aggregation
> ; <TEST=DE3>
> ;59
> select distinct region, avg(discount_rt) / 100.0 from prospects \
 (cont) >  group by region \
 (cont) > having REGION not in ('MW','SW') and avg(discount_rt) / 100.0 <> 0.0
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.PROSPECTS.REGION,,CHAR(2),,CHAR(2)
2,Expr,"AVG(PROSPECTS.DISCOUNT_RT) / 100.0",,DOUBLE(8),,C STRING(33)]
[ORDER_BY=NONE]

RE  AVG(PROSPECTS.DISCOUNT_RT) / 100  
--  --------------------------------  
0 rows returned
> ; <TEST=DE4>
> ;60
> select distinct sum(total) as sumtotal from orders \
 (cont) >  group by acct \
 (cont) > having sumtotal < 100.00
[SELECT_ITEMS=
1,Expr,"SUM(ORDERS.TOTAL)",SUMTOTAL,DOUBLE(8),,C STRING(33)]
[ORDER_BY=NONE]

SUMTOTAL                          
--------------------------------  
                        6.000000  
1 row returned
> ; <TEST=DE5>
> ;61
> select distinct min(discount_rt) from prospects \
 (cont) >  where cust_since <= 1992 and last_order >= '07-31-1998' \
 (cont) >  order by 1
[SELECT_ITEMS=
1,Expr,"MIN(PROSPECTS.DISCOUNT_RT)",,TINYINT(1),,C STRING(6)]
[ORDER_BY=NONE]

MIN(P  
-----  
   22  
1 row returned
> ;
> ; multiple tables
> ; <TEST=DMT1>
> ;62
> select distinct contact, tickler, initials from activity a join prospects p \
 (cont) >   using (acct)
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.P.CONTACT,,C STRING(24),,C STRING(24)
2,Column,STAR_ENV.STAR.A.TICKLER,,CHAR(2),,CHAR(2)
3,Column,STAR_ENV.STAR.A.INITIALS,,CHAR(4),,CHAR(4)]
[ORDER_BY=NONE]

CONTACT                  TI  INIT  
-----------------------  --  ----  
Anna Fireball            C1  SHIP  
Clint Dion               C1  SHIP  
Clint Dion               C2  SHIP  
Clint Dion               C3  SHIP  
Clint Dion               C4  SHIP  
Harriet Gradziel         C1  SHIP  
Harriet Gradziel         C2  SHIP  
Harriet Gradziel         C3  SHIP  
Harriet Gradziel         C4  SHIP  
Jack Niehause            C1  SHIP  
Jack Niehause            C2  SHIP  
Joanne Meyer             C1  SHIP  
Joanne Meyer             C2  SHIP  
Joanne Meyer             C3  SHIP  
Joanne Meyer             C4  SHIP  
Joanne Meyer             PC  EFR   
Mark Trasko              C1  SHIP  
Mark Trasko              C2  SHIP  
Mark Trasko              C3  SHIP  
Mark Trasko              C4  SHIP  
Mark Trasko              MF  SHIP  
Mark Trasko              RC  TJK   
Marty Kincaid            C1  SHIP  
Marty Kincaid            C2  SHIP  
Marty Kincaid            C3  SHIP  
Marty Kincaid            C4  SHIP  
Marty Kincaid            MF  SHIP  
Michelle Behrman         C1  SHIP  
Roxanne Dunagan          C1  SHIP  
Roxanne Dunagan          C2  SHIP  
Victor Warfield          C1  SHIP  
Victor Warfield          C2  SHIP  
Victor Warfield          C3  SHIP  
Victor Warfield          C4  SHIP  
Victor Warfield          RC  JJK   
35 rows returned
> ; <TEST=DMT2>
> ;63
> select distinct contact, source from prospects p, orders o \
 (cont) >  where o.acct = p.acct and \
 (cont) >        p.last_order <= '12-31-1996' and \
 (cont) >        ((p.region = 'MW' or o.tax_state in ('CO', 'KS', 'NE', 'IL')) \
 (cont) >         and (o.total >= 1000.00 or o.quantity > 100)) \
 (cont) >  order by contact
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.P.CONTACT,,C STRING(24),,C STRING(24)
2,Column,STAR_ENV.STAR.O.SOURCE,,TINYINT(1),,C STRING(6)]
[ORDER_BY=1]

CONTACT                  SOURC  
-----------------------  -----  
Joanne Meyer                 4  
Joanne Meyer                 5  
Joanne Meyer                 6  
3 rows returned
> ; <TEST=DMT3>
> ;64
> select top 3 distinct cost * quantity, total  from products p, orders o \
 (cont) >  where p.product_no = o.product_no and \
 (cont) >        (o.quantity >= 10 or p.wholesale > 1000.00) \
 (cont) >  order by total
[SELECT_ITEMS=
1,Expr,"P.COST * O.QUANTITY",,DOUBLE(8),,C STRING(33)
2,Column,STAR_ENV.STAR.O.TOTAL,,FLOAT(4),,C STRING(33)]
[ORDER_BY=2]

P.COST * O.QUANTITY               TOTAL                             
--------------------------------  --------------------------------  
                       12.000000                          9.360000  
                       20.000000                         18.000000  
                       54.000000                         42.119999  
3 rows returned
> ; <TEST=DMT4>
> ;65
> select distinct category, avg(wholesale), avg(total) from products p, orders o \
 (cont) >  where p.product_no = o.product_no and \
 (cont) >        (o.quantity >= 10 or p.wholesale > 1000.00) \
 (cont) >  group by category
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.P.CATEGORY,,INT(4),,C STRING(12)
2,Expr,"AVG(P.WHOLESALE)",,DOUBLE(8),,C STRING(33)
3,Expr,"AVG(O.TOTAL)",,DOUBLE(8),,C STRING(33)]
[ORDER_BY=NONE]

CATEGORY     AVG(P.WHOLESALE)                  
-----------  --------------------------------  
AVG(O.TOTAL)                      
--------------------------------  
         23                        136.665001  
                     2644.200073  
         31                       1660.158954  
                     8214.429288  
         41                        285.709991  
                     5616.000000  
         43                        553.569992  
                     9525.750000  
         51                        121.430000  
                     2254.200195  
         52                         50.000000  
                      791.699982  
         53                        110.001667  
                     1590.830012  
         61                        190.476669  
                     3263.000000  
        101                          0.770000  
                        9.360000  
        103                          1.540000  
                       18.000000  
        104                          2.310000  
                       42.119999  
11 rows returned
> ; <TEST=DMT5>
> ;66
> select distinct sum(p.discount_rt/100.0 * o.amount) from orders o join prospects p \
 (cont) >  on p.acct = o.acct \
 (cont) > having sum(p.discount_rt/100.0 * o.amount) between 1000.00 and 10000.00
[SELECT_ITEMS=
1,Expr,"SUM(P.DISCOUNT_RT / 100.0 * O.AMOUNT)",,DOUBLE(8),,C STRING(33)]
[ORDER_BY=NONE]

SUM(P.DISCOUNT_RT / 100.0 * O.AM  
--------------------------------  
0 rows returned
> ; Test reuse
> ; <TEST=DMT5r>
> ;67
> select distinct sum(p.discount_rt/100.0 * o.amount) from orders o, prospects p \
 (cont) >  where p.acct = o.acct \
 (cont) > having sum(p.discount_rt/100.0 * o.amount) between 1000.00 and 10000.00
[SELECT_ITEMS=
1,Expr,"SUM(P.DISCOUNT_RT / 100.0 * O.AMOUNT)",,DOUBLE(8),,C STRING(33)]
[ORDER_BY=NONE]

SUM(P.DISCOUNT_RT / 100.0 * O.AM  
--------------------------------  
0 rows returned
> ;
> ;
> ; <SECTION=AGG(DISTINCT)>
> ;
> ;Tests sum/avg(distinct col)
> ;
> ; <TEST=AGD1>
> ;68
> select avg(distinct cr_limit), count(distinct cr_limit) from prospects
[SELECT_ITEMS=
1,Expr,"AVG(DISTINCT PROSPECTS.CR_LIMIT)",,DOUBLE(8),,C STRING(33)
2,Expr,"COUNT(DISTINCT PROSPECTS.CR_LIMIT)",,UNS INT(4),,C STRING(11)]
[ORDER_BY=NONE]

AVG(DISTINCT PROSPECTS.CR_LIMIT)  COUNT(DIST  
--------------------------------  ----------  
                       23.000000           5  
1 row returned
> ; <TEST=AGD2>
> ;69
> select sum(distinct quantity) from orders \
 (cont) >  where amount < 10 \
 (cont) >  group by pmt_method
[SELECT_ITEMS=
1,Expr,"SUM(DISTINCT ORDERS.QUANTITY)",,DOUBLE(8),,C STRING(33)]
[ORDER_BY=NONE]

SUM(DISTINCT ORDERS.QUANTITY)     
--------------------------------  
                        1.000000  
                       19.000000  
                        1.000000  
                       11.000000  
                        1.000000  
                        1.000000  
                       13.000000  
                        1.000000  
8 rows returned
> ; Test reuse
> ; <TEST=AGD2r>
> ;70
> select sum(distinct quantity) from orders \
 (cont) >  where amount < 10 \
 (cont) >  group by pmt_method
[SELECT_ITEMS=
1,Expr,"SUM(DISTINCT ORDERS.QUANTITY)",,DOUBLE(8),,C STRING(33)]
[ORDER_BY=NONE]

SUM(DISTINCT ORDERS.QUANTITY)     
--------------------------------  
                        1.000000  
                       19.000000  
                        1.000000  
                       11.000000  
                        1.000000  
                        1.000000  
                       13.000000  
                        1.000000  
8 rows returned
> ; <TEST=AGD3>
> ;71
> select 100 * avg(distinct total) bigtotal, pmt_method, source \
 (cont) >   from orders \
 (cont) >  group by source, pmt_method \
 (cont) > having bigtotal between 10000 and 1000000.00
[SELECT_ITEMS=
1,Expr,"100 * AVG(DISTINCT ORDERS.TOTAL)",BIGTOTAL,DOUBLE(8),,C STRING(33)
2,Column,STAR_ENV.STAR.ORDERS.PMT_METHOD,,TINYINT(1),,C STRING(6)
3,Column,STAR_ENV.STAR.ORDERS.SOURCE,,TINYINT(1),,C STRING(6)]
[ORDER_BY=NONE]

BIGTOTAL                          PMT_M  SOURC  
--------------------------------  -----  -----  
                    14350.000207      1      1  
                    38219.999695      2      1  
                    35879.998779      4      1  
                    89700.000000      5      1  
                    91130.000051      6      1  
                   132990.000343      8      1  
                    15990.000153      9      1  
                   136292.006667     10      1  
                    19109.999847      2      2  
                    12479.999924      7      2  
                    89505.000305      8      2  
                    31200.000000      9      2  
                    69706.001790     10      2  
                   183300.000000      4      3  
                    21439.999390      5      3  
                    86839.999898      7      3  
                    82913.998779      8      3  
                    18000.000000      9      3  
                    24960.000610     10      3  
                   183300.000000      3      4  
                   163800.000000      6      4  
                   105689.999390      7      4  
                   175500.000000      9      4  
                   187876.004028      1      5  
                    59400.000095      2      5  
                   185718.005371      3      5  
                   102609.002686      4      5  
                   642300.000000      5      5  
                   339272.993307      6      5  
                   302302.000157      9      5  
                   147589.000956     10      5  
                   422040.000430      1      6  
                   154537.500119      2      6  
                   252448.997965      3      6  
                    82348.000081      4      6  
                    57092.001597      5      6  
                   387383.570993      6      6  
                    58021.999963      7      6  
                   268755.818347      8      6  
                   185684.307042      9      6  
                    78873.602154     10      6  
41 rows returned
> ; <TEST=AGD4>
> ;72
> select avg(cost) - avg(distinct wholesale) neg from products \
 (cont) >  where (description like '%Computer%' or category < 30) and wholesale > 100 \
 (cont) >  group by category \
 (cont) > having neg > -10.00
[SELECT_ITEMS=
1,Expr,"AVG(PRODUCTS.COST) - AVG(DISTINCT PRODUCTS.WHOLESALE)",NEG,DOUBLE(8),,C STRING(33)]
[ORDER_BY=NONE]

NEG                               
--------------------------------  
                      129.164993  
                       53.331668  
                      150.000000  
                       85.002499  
                       65.556666  
                      656.085281  
6 rows returned
> ; <TEST=AGD5>
> ;73
> select sum(distinct cr_limit * 1000) * (1 - avg(distinct discount_rt / 100.0)) \
 (cont) >   from prospects where cust_since <= 1992 and last_order >= '07-31-1998'
[SELECT_ITEMS=
1,Expr,"SUM(DISTINCT PROSPECTS.CR_LIMIT * 1000) * 1 - AVG(DISTINCT PROSPECTS.DISCOUNT_RT / 100.0)",,DOUBLE(8),,C STRING(33)]
[ORDER_BY=NONE]

SUM(DISTINCT PROSPECTS.CR_LIMIT   
--------------------------------  
                        0.000000  
1 row returned
> ; <TEST=AGD6>
> ;74
> select (discount/100.0) * sum(total), quantity * sum(distinct amount) \
 (cont) >   from orders \
 (cont) >  group by discount, quantity
[SELECT_ITEMS=
1,Expr,"ORDERS.DISCOUNT / 100.0 * SUM(ORDERS.TOTAL)",,DOUBLE(8),,C STRING(33)
2,Expr,"ORDERS.QUANTITY * SUM(DISTINCT ORDERS.AMOUNT)",,DOUBLE(8),,C STRING(33)]
[ORDER_BY=NONE]

ORDERS.DISCOUNT / 100.0 * SUM(OR  ORDERS.QUANTITY * SUM(DISTINCT O  
--------------------------------  --------------------------------  
                        0.000000                          6.000000  
                     1395.180000                       8460.900000  
                       72.000000                        720.000000  
                     1485.000000                      14850.000000  
                       36.000000                        360.000000  
                        1.800000                         18.000000  
                       97.200000                        972.000000  
                     2808.000000                      28080.000000  
                     6840.000000                      68400.000000  
                     3402.000000                      34020.000000  
                    17839.879255                      23353.979998  
                      171.600000                        780.000000  
                     2450.962852                      11140.740234  
                      253.968005                       1154.400024  
                       43.758002                        198.900003  
                     1276.703996                       5803.199982  
                     3123.120000                      14196.000000  
                     1084.512021                       4929.600098  
                      293.435997                       1333.799973  
                     4924.920000                      22385.998993  
                     8958.549531                      40720.680054  
                     4511.707192                      20507.759963  
                     9851.212690                      44778.240143  
                     6748.341089                      30674.278645  
                     1016.730000                       4621.500092  
                      495.924043                       2254.200104  
                     6217.754432                      28262.520053  
                    23122.757109                     105103.440186  
                     1372.800000                       6240.000000  
29 rows returned
> ; <TEST=AGD7>
> ;75
> select quantity * avg(amount) - quantity * avg(distinct amount), \
 (cont) >        count(amount), count(distinct amount) \
 (cont) >   from orders where amount < 10 \
 (cont) >  group by quantity, pmt_method
[SELECT_ITEMS=
1,Expr,"ORDERS.QUANTITY * AVG(ORDERS.AMOUNT) - ORDERS.QUANTITY * AVG(DISTINCT ORDERS.AMOUNT)",,DOUBLE(8),,C STRING(33)
2,Expr,"COUNT(ORDERS.AMOUNT)",,UNS INT(4),,C STRING(11)
3,Expr,"COUNT(DISTINCT ORDERS.AMOUNT)",,UNS INT(4),,C STRING(11)]
[ORDER_BY=NONE]

ORDERS.QUANTITY * AVG(ORDERS.AMO  COUNT(ORDE  COUNT(DIST  
--------------------------------  ----------  ----------  
                        0.000000           2           2  
                        0.000000           1           1  
                        0.000000           3           3  
                        0.000000           3           3  
                        0.000000           2           2  
                        0.000000           2           2  
                        0.000000           3           3  
                       -0.650000           3           2  
                        0.000000           1           1  
                        0.000000           1           1  
                        0.000000           1           1  
11 rows returned
> ; <TEST=AGD8>
> ;76
> select sum(distinct amount - ((discount/100.0) * amount)) + avg(total) / quantity \
 (cont) >   from orders \
 (cont) >  where amount < 100.00 or quantity between 5 and 10 \
 (cont) >  group by status, quantity
[SELECT_ITEMS=
1,Expr,"SUM(DISTINCT ORDERS.AMOUNT - ORDERS.DISCOUNT / 100.0 * ORDERS.AMOUNT) + AVG(ORDERS.TOTAL) / ORDERS.QUANTITY",,DOUBLE(8),,C STRING(33)]
[ORDER_BY=NONE]

SUM(DISTINCT ORDERS.AMOUNT - ORD  
--------------------------------  
                      190.179595  
                      124.955995  
                      517.855007  
                       50.918401  
                     3842.465997  
                     2257.840000  
                      851.736016  
                      189.695997  
                     2494.527921  
                      114.398400  
                       40.263602  
                        4.165200  
                       69.420000  
13 rows returned
> ; <TEST=AGD9>
> ;77
> select $round(quantity * sum(distinct amount - ((discount/100.0) * amount)) \
 (cont) >        - avg(distinct total) / quantity, 2), count(total), count(*), \
 (cont) >        status, quantity, acct \
 (cont) >   from orders \
 (cont) >  group by status, quantity, acct
[SELECT_ITEMS=
1,Expr,"$ROUND(ORDERS.QUANTITY * SUM(DISTINCT ORDERS.AMOUNT - ORDERS.DISCOUNT / 100.0 * ORDERS.AMOUNT) - AVG(DISTINCT ORDERS.TOTAL) / ORDER",,DOUBLE(8),,C STRING(33)
2,Expr,"COUNT(ORDERS.TOTAL)",,UNS INT(4),,C STRING(11)
3,Expr,"COUNT('*')",,UNS INT(4),,C STRING(11)
4,Column,STAR_ENV.STAR.ORDERS.STATUS,,CHAR(2),,CHAR(2)
5,Column,STAR_ENV.STAR.ORDERS.QUANTITY,,TINYINT(1),,C STRING(6)
6,Column,STAR_ENV.STAR.ORDERS.ACCT,,INT(4),,C STRING(12)]
[ORDER_BY=NONE]

$ROUND(ORDERS.QUANTITY * SUM(DIS  COUNT(ORDE  COUNT('*')  ST  QUANT  
--------------------------------  ----------  ----------  --  -----  
ACCT         
-----------  
                     3595.590000           7           7  CN      1  
          1  
                      586.870000           1           1  CN     12  
          1  
                    17358.390000         110         110  SH      1  
          1  
                     7144.760000          26          26  SH      1  
          2  
                        0.000000           1           1  SH      1  
          3  
                      413.400000           2           2  SH      2  
          1  
                     7451.920000           3           3  SH      3  
          1  
                      756.130000           2           2  SH      4  
          1  
                      468.000000           1           1  SH      4  
          2  
                      135.250000           2           2  SH      5  
          1  
                     4042.900000           2           2  SH      6  
          1  
                    12127.500000           2           2  SH      6  
          2  
                    10396.880000           3           3  SH      7  
          1  
                     3228.890000           1           1  SH      8  
          1  
                      279.000000           1           1  SH      8  
          2  
                      966.260000           2           2  SH      9  
          1  
                    16341.780000           2           2  SH     10  
          1  
                       14.400000           1           1  SH     10  
          2  
                    30528.170000           3           3  SH     11  
          1  
                    14519.590000           2           2  SH     12  
          1  
                      793.800000           1           1  SH     12  
          2  
                    34238.130000           5           5  SH     13  
          1  
                    23112.000000           1           1  SH     13  
          2  
                    22830.430000           2           2  SH     14  
          1  
                     3450.720000           2           2  SH     15  
          1  
                    59422.500000           2           2  SH     16  
          2  
                     1625.680000           1           1  SH     17  
          1  
                    21730.740000           5           5  SH     18  
          1  
                    28728.000000           1           1  SH     18  
          2  
                    80874.330000           5           5  SH     19  
          1  
                     4555.200000           1           1  SH     20  
          1  
31 rows returned
> ; <TEST=AGD10>
> ;78
> select quantity * sum(distinct amount - ((discount/100.0) * amount)) \
 (cont) >        - avg(distinct total) / quantity, count(total), count(*), \
 (cont) >        status, quantity, acct \
 (cont) >   from orders \
 (cont) >  where amount < 100.00 or quantity between 5 and 10 \
 (cont) >  group by status, quantity, acct \
 (cont) > having count(*) > 100 \
 (cont) >  order by 6,5,4,3,2,1
[SELECT_ITEMS=
1,Expr,"ORDERS.QUANTITY * SUM(DISTINCT ORDERS.AMOUNT - ORDERS.DISCOUNT / 100.0 * ORDERS.AMOUNT) - AVG(DISTINCT ORDERS.TOTAL) / ORDERS.QUANT",,DOUBLE(8),,C STRING(33)
2,Expr,"COUNT(ORDERS.TOTAL)",,UNS INT(4),,C STRING(11)
3,Expr,"COUNT('*')",,UNS INT(4),,C STRING(11)
4,Column,STAR_ENV.STAR.ORDERS.STATUS,,CHAR(2),,CHAR(2)
5,Column,STAR_ENV.STAR.ORDERS.QUANTITY,,TINYINT(1),,C STRING(6)
6,Column,STAR_ENV.STAR.ORDERS.ACCT,,INT(4),,C STRING(12)]
[ORDER_BY=6,5,4,3,2,1]

ORDERS.QUANTITY * SUM(DISTINCT O  COUNT(ORDE  COUNT('*')  ST  QUANT  
--------------------------------  ----------  ----------  --  -----  
ACCT         
-----------  
0 rows returned
> ; Test reuse
> ; <TEST=AGD10r>
> ;79
> select quantity * sum(distinct amount - ((discount/100.0) * amount)) \
 (cont) >        - avg(distinct total) / quantity, count(total), count(*), \
 (cont) >        status, quantity, acct \
 (cont) >   from orders \
 (cont) >  where amount < 100.00 or quantity between 5 and 10 \
 (cont) >  group by status, quantity, acct \
 (cont) > having count(*) > 100 \
 (cont) >  order by 6,5,4,3,2,1
[SELECT_ITEMS=
1,Expr,"ORDERS.QUANTITY * SUM(DISTINCT ORDERS.AMOUNT - ORDERS.DISCOUNT / 100.0 * ORDERS.AMOUNT) - AVG(DISTINCT ORDERS.TOTAL) / ORDERS.QUANT",,DOUBLE(8),,C STRING(33)
2,Expr,"COUNT(ORDERS.TOTAL)",,UNS INT(4),,C STRING(11)
3,Expr,"COUNT('*')",,UNS INT(4),,C STRING(11)
4,Column,STAR_ENV.STAR.ORDERS.STATUS,,CHAR(2),,CHAR(2)
5,Column,STAR_ENV.STAR.ORDERS.QUANTITY,,TINYINT(1),,C STRING(6)
6,Column,STAR_ENV.STAR.ORDERS.ACCT,,INT(4),,C STRING(12)]
[ORDER_BY=6,5,4,3,2,1]

ORDERS.QUANTITY * SUM(DISTINCT O  COUNT(ORDE  COUNT('*')  ST  QUANT  
--------------------------------  ----------  ----------  --  -----  
ACCT         
-----------  
0 rows returned
> ; <TEST=AGD11>
> ;80
> select quantity * sum(distinct amount - ((discount/100.0) * amount)) \
 (cont) >        - avg(distinct total) / quantity, count(total), count(*), \
 (cont) >        status, quantity, acct \
 (cont) >   from orders \
 (cont) >  where amount < 100.00 or quantity between 5 and 10 \
 (cont) >  group by status, quantity, acct \
 (cont) >  order by 6,5,4,3,2,1
[SELECT_ITEMS=
1,Expr,"ORDERS.QUANTITY * SUM(DISTINCT ORDERS.AMOUNT - ORDERS.DISCOUNT / 100.0 * ORDERS.AMOUNT) - AVG(DISTINCT ORDERS.TOTAL) / ORDERS.QUANT",,DOUBLE(8),,C STRING(33)
2,Expr,"COUNT(ORDERS.TOTAL)",,UNS INT(4),,C STRING(11)
3,Expr,"COUNT('*')",,UNS INT(4),,C STRING(11)
4,Column,STAR_ENV.STAR.ORDERS.STATUS,,CHAR(2),,CHAR(2)
5,Column,STAR_ENV.STAR.ORDERS.QUANTITY,,TINYINT(1),,C STRING(6)
6,Column,STAR_ENV.STAR.ORDERS.ACCT,,INT(4),,C STRING(12)]
[ORDER_BY=6,5,4,3,2,1]

ORDERS.QUANTITY * SUM(DISTINCT O  COUNT(ORDE  COUNT('*')  ST  QUANT  
--------------------------------  ----------  ----------  --  -----  
ACCT         
-----------  
                       76.299598           3           3  CN      1  
          1  
                      328.514547          30          30  SH      1  
          1  
                      135.252002           2           2  SH      5  
          1  
                     4042.895987           2           2  SH      6  
          1  
                    10396.880000           3           3  SH      7  
          1  
                     3228.888064           1           1  SH      8  
          1  
                      966.263979           2           2  SH      9  
          1  
                    16341.779214           2           2  SH     10  
          1  
                      586.871974           1           1  CN     12  
          1  
                        6.520800           1           1  SH     12  
          1  
                      224.390408           1           1  SH     14  
          1  
                       30.513599           1           1  SH     18  
          1  
                      538.980000           1           1  SH     19  
          1  
                      102.960000           7           7  SH      1  
          2  
                    12127.500000           2           2  SH      6  
          2  
                      279.000000           1           1  SH      8  
          2  
                       14.400000           1           1  SH     10  
          2  
                      793.800000           1           1  SH     12  
          2  
                        0.000000           1           1  SH      1  
          3  
19 rows returned
> ;
> ; multiple tables
> ; <TEST=AGDMT1>
> ;81
> select sum(distinct quantity + 1000), avg(distinct quantity *100), \
 (cont) >        0.5 * sum(distinct cr_limit), avg(distinct cr_limit) \
 (cont) >   from orders o, prospects p \
 (cont) >  where o.acct = p.acct and \
 (cont) >        (order_date > '01-01-1996' or quantity between 1 and 5 \
 (cont) >        or sales_tax < 4.00) and company like '%Systems%' \
 (cont) >  group by cr_limit \
 (cont) > having sum(cr_limit) < 10
[SELECT_ITEMS=
1,Expr,"SUM(DISTINCT O.QUANTITY + 1000)",,DOUBLE(8),,C STRING(33)
2,Expr,"AVG(DISTINCT O.QUANTITY * 100)",,DOUBLE(8),,C STRING(33)
3,Expr,"0.5 * SUM(DISTINCT P.CR_LIMIT)",,DOUBLE(8),,C STRING(33)
4,Expr,"AVG(DISTINCT P.CR_LIMIT)",,DOUBLE(8),,C STRING(33)]
[ORDER_BY=NONE]

SUM(DISTINCT O.QUANTITY + 1000)   AVG(DISTINCT O.QUANTITY * 100)    
--------------------------------  --------------------------------  
0.5 * SUM(DISTINCT P.CR_LIMIT)    AVG(DISTINCT P.CR_LIMIT)          
--------------------------------  --------------------------------  
                     8064.000000                        800.000000  
                        0.000000                          0.000000  
1 row returned
> ; Test reuse
> ; <TEST=AGDMT1r>
> ;82
> select sum(distinct quantity + 1000), avg(distinct quantity *100), \
 (cont) >        0.5 * sum(distinct cr_limit), avg(distinct cr_limit) \
 (cont) >   from orders o, prospects p \
 (cont) >  where o.acct = p.acct and \
 (cont) >        (order_date > '01-01-1996' or quantity between 1 and 5 \
 (cont) >        or sales_tax < 4.00) and company like '%Systems%' \
 (cont) >  group by cr_limit \
 (cont) > having sum(cr_limit) < 10
[SELECT_ITEMS=
1,Expr,"SUM(DISTINCT O.QUANTITY + 1000)",,DOUBLE(8),,C STRING(33)
2,Expr,"AVG(DISTINCT O.QUANTITY * 100)",,DOUBLE(8),,C STRING(33)
3,Expr,"0.5 * SUM(DISTINCT P.CR_LIMIT)",,DOUBLE(8),,C STRING(33)
4,Expr,"AVG(DISTINCT P.CR_LIMIT)",,DOUBLE(8),,C STRING(33)]
[ORDER_BY=NONE]

SUM(DISTINCT O.QUANTITY + 1000)   AVG(DISTINCT O.QUANTITY * 100)    
--------------------------------  --------------------------------  
0.5 * SUM(DISTINCT P.CR_LIMIT)    AVG(DISTINCT P.CR_LIMIT)          
--------------------------------  --------------------------------  
                     8064.000000                        800.000000  
                        0.000000                          0.000000  
1 row returned
> ; <TEST=AGDMT2>
> ;83
> select sum(distinct cr_limit) * (discount / 100.0), \
 (cont) >        $trunc(quantity * sum(distinct wholesale - ((discount/100.0) * amount)), 2), \
 (cont) >        - avg(distinct total) / quantity, count(total), count(*) \
 (cont) >   from orders, prospects, products \
 (cont) >  where orders.acct = prospects.acct and \
 (cont) >        products.product_no = orders.product_no \
 (cont) >  group by quantity, discount \
 (cont) >  order by 2
[SELECT_ITEMS=
1,Expr,"SUM(DISTINCT PROSPECTS.CR_LIMIT) * ORDERS.DISCOUNT / 100.0",,DOUBLE(8),,C STRING(33)
2,Expr,"$TRUNC(ORDERS.QUANTITY * SUM(DISTINCT PRODUCTS.WHOLESALE - ORDERS.DISCOUNT / 100.0 * ORDERS.AMOUNT),2)",,DOUBLE(8),,C STRING(33)
3,Expr,"AVG(DISTINCT ORDERS.TOTAL) * -1 / ORDERS.QUANTITY",,DOUBLE(8),,C STRING(33)
4,Expr,"COUNT(ORDERS.TOTAL)",,UNS INT(4),,C STRING(11)
5,Expr,"COUNT('*')",,UNS INT(4),,C STRING(11)]
[ORDER_BY=2]

SUM(DISTINCT PROSPECTS.CR_LIMIT)  $TRUNC(ORDERS.QUANTITY * SUM(DIS  
--------------------------------  --------------------------------  
AVG(DISTINCT ORDERS.TOTAL) * -1   COUNT(ORDE  COUNT('*')  
--------------------------------  ----------  ----------  
                        0.000000                          4.610000  
                       -6.000000           1           1  
                        2.500000                         13.590000  
                       -1.800000           1           1  
                        0.000000                        144.390000  
                      -19.890001           2           2  
                        2.500000                        249.670000  
                      -45.000000           1           1  
                        2.500000                        499.440000  
                     -180.000000           1           1  
                        0.000000                        542.690000  
                     -195.000000           2           2  
                        2.500000                        674.280000  
                      -81.000000           1           1  
                        0.000000                        803.190000  
                     -144.300003           2           2  
                        0.000000                        928.040000  
                      -74.099999           2           2  
                        0.000000                       1568.380000  
                     -132.600011           1           1  
                        0.000000                       3072.560000  
                     -154.050000           2           2  
                        0.000000                       3429.800000  
                     -616.200012           1           1  
                        0.000000                       4037.610000  
                     -483.599998           2           2  
                        0.000000                       4341.390000  
                     -312.000000           1           1  
                        2.500000                       5826.750000  
                     -470.050000          26          26  
                        0.000000                       7751.160000  
                    -1237.860026           3           3  
                        0.000000                       9876.850000  
                     -676.000000           3           3  
                        2.500000                      10300.670000  
                    -1237.500000           2           2  
                        0.000000                      14269.010000  
                     -569.659999           3           3  
                        0.000000                      15575.070000  
                    -1119.300000           2           2  
                        0.000000                      16425.010000  
                     -569.609268         117         117  
                        2.500000                      19477.770000  
                    -2160.000000           1           1  
                        0.000000                      19486.600000  
                     -314.028002           5           5  
                        0.000000                      21341.530000  
                    -1095.509917           2           2  
                        2.500000                      23598.000000  
                    -1890.000000           1           1  
                        0.000000                      28331.440000  
                    -1233.959991           3           3  
                        0.000000                      31154.420000  
                     -688.895992           5           5  
                        2.500000                      47445.750000  
                    -2137.500000           2           2  
                        0.000000                      73125.730000  
                    -1106.352015           5           5  
29 rows returned
> ;
> ;
> ; <SECTION=WHERE-CLAUSE-OPT(no_aggs)>
> ;
> ;Tests where-clause optimization (without aggregations)
> ;
> ; <TEST=WO1>
> ;84
> select p.product_no \
 (cont) >   from orders o, products p \
 (cont) >   where o.product_no = p.product_no and \
 (cont) >         (o.quantity >= 10 or p.wholesale > 1000.00)
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.P.PRODUCT_NO,,CHAR(4),,CHAR(4)]
[ORDER_BY=NONE]

PROD  
----  
GUOC  
OSER  
C478  
C478  
C478  
H736  
H736  
H736  
H736  
IC9S  
IC9S  
IC9S  
IC9S  
IC9S  
IC9S  
G520  
G520  
G520  
G520  
G520  
G520  
G520  
G523  
G523  
G523  
G523  
G523  
G523  
G523  
DM20  
DM20  
DM20  
DM20  
DM20  
DM20  
DM20  
DM23  
DM23  
DM23  
A940  
A940  
A940  
A940  
A940  
A940  
A940  
A940  
P224  
P224  
P224  
P224  
P225  
P225  
P225  
P225  
P225  
N972  
N972  
N972  
N972  
EDMP  
H400  
H400  
HL6P  
HL6P  
P900  
T750  
L433  
S100  
N820  
PH65  
MPOP  
MPOP  
MTAC  
B290  
B290  
B390  
3RGS  
SSST  
3DST  
80 rows returned
> ; <TEST=WO2>
> ;85
> select top 5% acct, product_no, order_date from orders \
 (cont) >   where discount = 0 or quantity <= 5 or total < 22.5 \
 (cont) >   order by 1, 2, 3
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.ORDERS.ACCT,,INT(4),,C STRING(12)
2,Column,STAR_ENV.STAR.ORDERS.PRODUCT_NO,,CHAR(4),,CHAR(4)
3,Column,STAR_ENV.STAR.ORDERS.ORDER_DATE,,ODX DATE(4),YYYYMMDD,C STRING(17)]
[ORDER_BY=1,2,3]

ACCT         PROD  ORDER_DATE        
-----------  ----  ----------------  
          1  3DST      Aug 20, 1993  
          1  3MTP      May 20, 1995  
          1  3P23      Jul 20, 1995  
          1  3RGS      Feb 20, 1995  
          1  3SAD      Apr 20, 1990  
          1  3SAD      Jan 20, 1994  
          1  A940      Jan 20, 1993  
          1  A940      Oct 20, 1993  
8 rows returned
> ; <TEST=WO3>
> ;86
> select acct, initials, dt from activity \
 (cont) >   where (initials not like 'SH%' and initials not like '%J%') or tickler in ('MF', 'PC', 'RC')
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.ACTIVITY.ACCT,,INT(4),,C STRING(12)
2,Column,STAR_ENV.STAR.ACTIVITY.INITIALS,,CHAR(4),,CHAR(4)
3,Column,STAR_ENV.STAR.ACTIVITY.DT,,ODX DATE(4),YYYYMMDD,C STRING(17)]
[ORDER_BY=NONE]

ACCT         INIT  DT                
-----------  ----  ----------------  
          1  TJK       Jun 17, 1993  
          1  SHIP      Jun 15, 1995  
          1  SHIP      Mar 15, 1997  
          2  EFR        Dec 3, 1997  
          3  SHIP      Jan 15, 1996  
          4  JJK       Oct 13, 1996  
6 rows returned
> ; Test reuse
> ; <TEST=WO3r>
> ;87
> select acct, initials, dt from activity \
 (cont) >   where (initials not like 'SH%' and initials not like '%J%') or tickler in ('MF', 'PC', 'RC')
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.ACTIVITY.ACCT,,INT(4),,C STRING(12)
2,Column,STAR_ENV.STAR.ACTIVITY.INITIALS,,CHAR(4),,CHAR(4)
3,Column,STAR_ENV.STAR.ACTIVITY.DT,,ODX DATE(4),YYYYMMDD,C STRING(17)]
[ORDER_BY=NONE]

ACCT         INIT  DT                
-----------  ----  ----------------  
          1  TJK       Jun 17, 1993  
          1  SHIP      Jun 15, 1995  
          1  SHIP      Mar 15, 1997  
          2  EFR        Dec 3, 1997  
          3  SHIP      Jan 15, 1996  
          4  JJK       Oct 13, 1996  
6 rows returned
> ; <TEST=WO4>
> ;88
> select product_no from products \
 (cont) >   where description like '%Computer' or (category < 30 and wholesale > 100)
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.PRODUCTS.PRODUCT_NO,,CHAR(4),,CHAR(4)]
[ORDER_BY=NONE]

PROD  
----  
A940  
BMCR  
BMED  
BMLF  
C478  
DM20  
DM23  
G520  
G523  
GEHE  
GMLC  
GTLC  
GUOC  
H736  
IC9S  
N972  
OEDW  
OSEH  
OSER  
OSTC  
P224  
P225  
SCED  
SCFL  
SWDS  
SWFL  
26 rows returned
> ; <TEST=WO5>
> ;89
> select order_date, ((amount * quantity) - total) from orders \
 (cont) >   where ((order_date between '01-01-1996' and '12-31-1996' and quantity > 10) or \
 (cont) >         (order_date between '01-01-1995' and '12-31-1995' and (quantity > 10 or total > 10000))) \
 (cont) >         and tax_state = 'CO'
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.ORDERS.ORDER_DATE,,ODX DATE(4),YYYYMMDD,C STRING(17)
2,Expr,"ORDERS.AMOUNT * ORDERS.QUANTITY - ORDERS.TOTAL",,DOUBLE(8),,C STRING(33)]
[ORDER_BY=NONE]

ORDER_DATE        ORDERS.AMOUNT * ORDERS.QUANTITY   
----------------  --------------------------------  
    Aug 20, 1995                          0.000000  
    Mar 20, 1995                          0.000031  
    Feb 20, 1995                          0.000000  
    Aug 20, 1995                         -0.000092  
    Feb 20, 1995                          0.000000  
    Feb 20, 1996                          0.000000  
6 rows returned
> ; <TEST=WO6>
> ;90
> select d.description, p.description, s.description \
 (cont) >   from orders o, products p, dates d, statuses s \
 (cont) >  where (o.product_no = p.product_no and o.order_date = d.dt \
 (cont) >         and o.status = s.status) and \
 (cont) >         (s.description = 'Cancelled' or d.yr < 1991 \
 (cont) >         or o.discount = 0 or p.margin <= 30) order by d.dt, p.description
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.D.DESCRIPTION,,C STRING(32),,C STRING(32)
2,Column,STAR_ENV.STAR.P.DESCRIPTION,,C STRING(32),,C STRING(32)
3,Column,STAR_ENV.STAR.S.DESCRIPTION,,C STRING(32),,C STRING(32)]
[ORDER_BY=EXACT]

DESCRIPTION                      DESCRIPTION                      
-------------------------------  -------------------------------  
DESCRIPTION                      
-------------------------------  
Sat Jan 20 1990                  Deskjet 1000Cse                  
Shipped                          
Sat Jan 20 1990                  Double-Sided Tape                
Shipped                          
Sat Jan 20 1990                  FAX-290MC Fax Machine            
Shipped                          
Sat Jan 20 1990                  Quad Planning Pad                
Shipped                          
Sat Jan 20 1990                  Toner Cartridge                  
Shipped                          
Tue Feb 20 1990                  Aptiva C9S Computer              
Shipped                          
Tue Mar 20 1990                  820 Cellular Phone               
Shipped                          
Tue Mar 20 1990                  OfficeJet 300 Fax/Copier         
Shipped                          
Fri Apr 20 1990                  2000 G5-233 Computer             
Shipped                          
Fri Apr 20 1990                  Aptiva C9S Computer              
Shipped                          
Fri Apr 20 1990                  Spray Adhesives                  
Shipped                          
Sun May 20 1990                  Deskjet 672C                     
Shipped                          
Sun May 20 1990                  Dimension XPS M200 Computer      
Shipped                          
Sun May 20 1990                  EB-H65S Cellular Phone           
Shipped                          
Sun May 20 1990                  FAX-290MC Fax Machine            
Shipped                          
Sun May 20 1990                  LQ 2080 Dot Matrix Printer       
Shipped                          
Wed Jun 20 1990                  Aptiva C9S Computer              
Shipped                          
Wed Jun 20 1990                  Deskjet 1000Cse                  
Shipped                          
Wed Jun 20 1990                  KX-TC900 Cordless Phone          
Shipped                          
Wed Jun 20 1990                  Laserjet 6Lse                    
Shipped                          
Wed Jun 20 1990                  Platinum 2240 Computer           
Shipped                          
Wed Jun 20 1990                  Ready Systems 9725 Computer      
Shipped                          
Mon Aug 20 1990                  7220 Cordless Phone              
Shipped                          
Mon Aug 20 1990                  7220 Cordless Phone              
Shipped                          
Sat Oct 20 1990                  820 Cellular Phone               
Shipped                          
Sat Oct 20 1990                  FT-7505 Cordless Phone           
Shipped                          
Sat Oct 20 1990                  KX-TC160 Cordless Phone          
Shipped                          
Sat Oct 20 1990                  Meisterstuck Rollerball          
Cancelled                        
Tue Nov 20 1990                  4336 Cordless Phone              
Shipped                          
Tue Nov 20 1990                  Dimension XPS M200 Computer      
Shipped                          
Tue Nov 20 1990                  Drafting Mechanical Pencil       
Shipped                          
Tue Nov 20 1990                  Micro TAC Elite Cellular Phone   
Cancelled                        
Thu Dec 20 1990                  Deskjet 672C                     
Shipped                          
Thu Dec 20 1990                  Dimension XPS M200 Computer      
Shipped                          
Thu Dec 20 1990                  Ergonomic Chair                  
Shipped                          
Thu Dec 20 1990                  FAX-190 Fax Machine              
Shipped                          
Thu Dec 20 1990                  G5-200M Computer                 
Shipped                          
Thu Dec 20 1990                  KX-TC900 Cordless Phone          
Shipped                          
Thu Dec 20 1990                  Ready Systems 9725 Computer      
Shipped                          
Fri Sep 20 1991                  2000 G5-233 Computer             
Cancelled                        
Fri Dec 20 1991                  Multipurpose Paper               
Shipped                          
Mon Jan 20 1992                  Round Stic Ballpoint Pens        
Shipped                          
Fri Mar 20 1992                  Populous Cellular Phone          
Cancelled                        
Sat Feb 20 1993                  Better Ball Stick Pen            
Shipped                          
Fri Aug 20 1993                  Double-Sided Tape                
Shipped                          
Mon Sep 20 1993                  Round Stic Ballpoint Pens        
Shipped                          
Wed Oct 20 1993                  Toner Cartridge                  
Shipped                          
Mon Dec 20 1993                  Toner Cartridge                  
Shipped                          
Thu Jan 20 1994                  Spray Adhesives                  
Cancelled                        
Sun Mar 20 1994                  Dr. Grip Mechanical Pencils      
Shipped                          
Sun Mar 20 1994                  FT-7505 Cordless Phone           
Cancelled                        
Wed Apr 20 1994                  Multipurpose Paper               
Shipped                          
Fri May 20 1994                  Premium Copier Paper             
Shipped                          
Mon Jun 20 1994                  Advantage 9404 Computer          
Cancelled                        
Tue Dec 20 1994                  Acu-Pad Writing Pads (12)        
Shipped                          
Fri Jan 20 1995                  Embassy Writing Pads (12)        
Shipped                          
Wed Feb 8 1995                   25% Cotton Paper                 
Shipped                          
Mon Feb 20 1995                  Pavillion 7360 Computer          
Cancelled                        
Mon Feb 20 1995                  Removable Glue Stick             
Shipped                          
Mon Mar 20 1995                  Magic Tape                       
Shipped                          
Sat May 20 1995                  Magic Tape                       
Shipped                          
Tue Jun 20 1995                  Magic Tape                       
Shipped                          
Thu Jul 20 1995                  100% Cotton Paper                
Shipped                          
Thu Jul 20 1995                  Diskette Labels                  
Shipped                          
Thu Jul 20 1995                  Post-It Notes - 2x3 (12)         
Shipped                          
Fri Oct 20 1995                  Better Ball Stick Pen            
Shipped                          
Mon Nov 20 1995                  Speedpoint Staples               
Shipped                          
Wed Dec 20 1995                  Multipurpose Paper               
Shipped                          
Wed Dec 20 1995                  Paper Clips                      
Shipped                          
69 rows returned
> ; <TEST=WO7>
> ;91
> select a.initials, t.description from activity a join ticklers t \
 (cont) >   on (a.tickler = t.tickler) \
 (cont) >   where a.dt >= '01-01-1998' and t.description like '%Catalog'
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.A.INITIALS,,CHAR(4),,CHAR(4)
2,Column,STAR_ENV.STAR.T.DESCRIPTION,,C STRING(32),,C STRING(32)]
[ORDER_BY=NONE]

INIT  DESCRIPTION                      
----  -------------------------------  
SHIP  Mailed Spring Catalog            
SHIP  Mailed Summer Catalog            
SHIP  Mailed Spring Catalog            
SHIP  Mailed Summer Catalog            
SHIP  Mailed Spring Catalog            
SHIP  Mailed Summer Catalog            
SHIP  Mailed Spring Catalog            
SHIP  Mailed Summer Catalog            
SHIP  Mailed Spring Catalog            
SHIP  Mailed Summer Catalog            
SHIP  Mailed Spring Catalog            
SHIP  Mailed Summer Catalog            
SHIP  Mailed Spring Catalog            
SHIP  Mailed Summer Catalog            
SHIP  Mailed Spring Catalog            
SHIP  Mailed Summer Catalog            
SHIP  Mailed Spring Catalog            
SHIP  Mailed Spring Catalog            
18 rows returned
> ; <TEST=WO8>
> ;92
> select contact, f.description, m.description \
 (cont) >   from prospects p, mailings m, mailflags f \
 (cont) >  where (p.mailing = m.mailing and p.mailflag = f.mailflag) and \
 (cont) >         m.description = 'All' and f.description like '%catalogs%' \
 (cont) >         and f.description not like '%flyers%' \
 (cont) >  order by p.acct, m.mailing desc
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.P.CONTACT,,C STRING(24),,C STRING(24)
2,Column,STAR_ENV.STAR.F.DESCRIPTION,,C STRING(32),,C STRING(32)
3,Column,STAR_ENV.STAR.M.DESCRIPTION,,C STRING(32),,C STRING(32)]
[ORDER_BY=EXACT]

CONTACT                  DESCRIPTION                      
-----------------------  -------------------------------  
DESCRIPTION                      
-------------------------------  
Joanne Meyer             Mail catalogs only               
All                              
Roxanne Dunagan          Mail catalogs only               
All                              
2 rows returned
> ; <TEST=WO9>
> ;93
> select tax_state, region, last_order \
 (cont) >   from orders o, prospects p \
 (cont) >   where p.acct = o.acct and \
 (cont) >         p.last_order <= '12-31-1996' and \
 (cont) >         ((p.region = 'MW' or o.tax_state in ('CO', 'KS', 'NE', 'IL')) \
 (cont) >          and (o.total >= 1000.00 or o.quantity > 100)) \
 (cont) >   order by region desc, tax_state
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.O.TAX_STATE,,CHAR(2),,CHAR(2)
2,Column,STAR_ENV.STAR.P.REGION,,CHAR(2),,CHAR(2)
3,Column,STAR_ENV.STAR.P.LAST_ORDER,,ODX DATE(4),YYYYMMDD,C STRING(17)]
[ORDER_BY=2,1]

TA  RE  LAST_ORDER        
--  --  ----------------  
TX  MW      Jun 23, 1996  
TX  MW      Jun 23, 1996  
TX  MW      Jun 23, 1996  
TX  MW      Jun 23, 1996  
TX  MW      Jun 23, 1996  
TX  MW      Jun 23, 1996  
TX  MW      Jun 23, 1996  
TX  MW      Jun 23, 1996  
TX  MW      Jun 23, 1996  
TX  MW      Jun 23, 1996  
TX  MW      Jun 23, 1996  
11 rows returned
> ; Test reuse
> ; <TEST=WO9r>
> ;94
> select tax_state, region, last_order \
 (cont) >   from orders o, prospects p \
 (cont) >   where p.acct = o.acct and \
 (cont) >         p.last_order <= '12-31-1996' and \
 (cont) >         ((p.region = 'MW' or o.tax_state in ('CO', 'KS', 'NE', 'IL')) \
 (cont) >          and (o.total >= 1000.00 or o.quantity > 100)) \
 (cont) >   order by region desc, tax_state
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.O.TAX_STATE,,CHAR(2),,CHAR(2)
2,Column,STAR_ENV.STAR.P.REGION,,CHAR(2),,CHAR(2)
3,Column,STAR_ENV.STAR.P.LAST_ORDER,,ODX DATE(4),YYYYMMDD,C STRING(17)]
[ORDER_BY=2,1]

TA  RE  LAST_ORDER        
--  --  ----------------  
TX  MW      Jun 23, 1996  
TX  MW      Jun 23, 1996  
TX  MW      Jun 23, 1996  
TX  MW      Jun 23, 1996  
TX  MW      Jun 23, 1996  
TX  MW      Jun 23, 1996  
TX  MW      Jun 23, 1996  
TX  MW      Jun 23, 1996  
TX  MW      Jun 23, 1996  
TX  MW      Jun 23, 1996  
TX  MW      Jun 23, 1996  
11 rows returned
> ;
> ;
> ; <SECTION=WHERE-CLAUSE-OPT-$ODXID>
> ;
> ; Tests where-clause optimization following an explicit qualify
> ;
> ; <TEST=QWO1>
> ;95
> qualify prospects where company = 'systems'
4 PROSPECTS records qualify
> select company from prospects where cust_since = '1998' with odxid
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.PROSPECTS.COMPANY,,C STRING(60),,C STRING(60)]
[ORDER_BY=NONE]

COMPANY                                                      
-----------------------------------------------------------  
Strategic Systems Group                                      
Productive Systems                                           
Smith Information Management Systems                         
3 rows returned
> ; try a distinct
> ; <TEST=QWO2>
> ;96
> qualify prospects where company = 'systems'
4 PROSPECTS records qualify
> select distinct region from prospects where cust_since = '1998' with odxid
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.PROSPECTS.REGION,,CHAR(2),,CHAR(2)]
[ORDER_BY=NONE]

RE  
--  
MW  
SW  
2 rows returned
> ;<TEST=QWO3>
> ;97
> qualify activity where initials <> 'SHIP'
3 ACTIVITY records qualify
> select min(dt) from activity where tickler = 'RC' with odxid
[SELECT_ITEMS=
1,Expr,"MIN(ACTIVITY.DT)",,ODX DATE(4),YYYYMMDD,C STRING(17)]
[ORDER_BY=NONE]

MIN(ACTIVITY.DT)  
----------------  
    Jun 17, 1993  
1 row returned
> ; Test reuse
> ; <TEST=QWO3r>
> ;98
> qualify activity where initials <> 'SHIP'
3 ACTIVITY records qualify
> select min(dt) from activity where tickler = 'RC' with odxid
[SELECT_ITEMS=
1,Expr,"MIN(ACTIVITY.DT)",,ODX DATE(4),YYYYMMDD,C STRING(17)]
[ORDER_BY=NONE]

MIN(ACTIVITY.DT)  
----------------  
    Jun 17, 1993  
1 row returned
> ; try an ims agg
> ; <TEST=QWO4>
> ;99
> qualify orders where discount > 10
163 ORDERS records qualify
> select top 10% product_no, sum(amount), count(*), avg(quantity) from orders \
 (cont) >  where discount > 0 \
 (cont) >  group by product_no \
 (cont) >   with odxid
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.ORDERS.PRODUCT_NO,,CHAR(4),,CHAR(4)
2,Expr,"SUM(ORDERS.AMOUNT)",,DOUBLE(8),,C STRING(33)
3,Expr,"COUNT('*')",,UNS INT(4),,C STRING(11)
4,Expr,"AVG(ORDERS.QUANTITY)",,DOUBLE(8),,C STRING(33)]
[ORDER_BY=NONE]

PROD  SUM(ORDERS.AMOUNT)                COUNT('*')  
----  --------------------------------  ----------  
AVG(ORDERS.QUANTITY)              
--------------------------------  
3DST                          4.680000           2  
                        9.500000  
3MTP                          0.780000           1  
                        1.000000  
3P23                          4.680000           1  
                        1.000000  
3RGS                          0.780000           1  
                       12.000000  
3SAD                         14.040000           2  
                        1.000000  
A940                       8190.000000           5  
                        3.200000  
6 rows returned
> ; try an ims qualify
> ; <TEST=QWO5>
> ;100
> qualify orders where pt = 'H*' with ask
45 ORDERS records qualify
> select distinct acct, total from orders where tax_state = 'TX' with odxid
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.ORDERS.ACCT,,INT(4),,C STRING(12)
2,Column,STAR_ENV.STAR.ORDERS.TOTAL,,FLOAT(4),,C STRING(33)]
[ORDER_BY=NONE]

ACCT         TOTAL                             
-----------  --------------------------------  
          2                         31.500000  
          2                        180.000000  
          2                        360.000000  
          2                        450.000000  
          2                       2025.000000  
          2                       2160.000000  
6 rows returned
> ; try an 'or'
> ; <TEST=QWO6>
> ;101
> qualify orders where discount > 10
163 ORDERS records qualify
> select product_no from orders \
 (cont) >  where $rowid in $odxid or \
 (cont) >        (order_date between '02-14-1996' and '12-07-1996' and \
 (cont) >         not (amount < 100))
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.ORDERS.PRODUCT_NO,,CHAR(4),,CHAR(4)]
[ORDER_BY=NONE]

PROD  
----  
3DST  
3DST  
3MTP  
3P23  
3RGS  
3SAD  
3SAD  
A940  
A940  
A940  
A940  
A940  
AAWP  
ACPC  
AQPP  
B190  
B190  
B290  
B290  
B290  
B290  
B390  
B390  
B390  
B390  
B390  
B455  
B455  
B455  
B455  
B455  
BMED  
BRSP  
BRSP  
BTCT  
C478  
C478  
C478  
CGPP  
DM20  
DM20  
DM20  
DM20  
DM20  
DM20  
DM20  
DM23  
DM23  
DM23  
EDMP  
EDMP  
EDMP  
G520  
G520  
G520  
G520  
G520  
G520  
G523  
G523  
G523  
G523  
G523  
G523  
G523  
GEHE  
GUOC  
H100  
H100  
H100  
H100  
H100  
H100  
H400  
H400  
H400  
H400  
H400  
H672  
H672  
H672  
H672  
H672  
H672  
H672  
H736  
H736  
H736  
HL6P  
HL6P  
HL6P  
HL6P  
HL6P  
HL6P  
HLTC  
HLTC  
HO30  
HO30  
HO30  
HO30  
HO30  
HPMP  
HPMP  
IC9S  
IC9S  
IC9S  
IC9S  
L433  
L722  
L722  
MMRB  
MPOP  
MPOP  
MPOP  
MPOP  
MPOP  
MTAC  
MTAC  
N820  
N820  
N820  
N820  
N972  
N972  
N972  
N972  
OSER  
OSER  
OSER  
OSTC  
P160  
P160  
P160  
P224  
P224  
P224  
P224  
P225  
P225  
P900  
P900  
P900  
P900  
P900  
P900  
P900  
PBSP  
PBSP  
PDMP  
PH65  
PH65  
PH65  
S100  
S100  
S100  
S100  
SCDR  
SCFP  
T750  
T750  
T750  
T750  
T750  
XPCP  
164 rows returned
> ;
> ;
> ; <SECTION=HAVING>
> ; (in addition to those tested above)
> ;
> ; <TEST=H1>
> ;102
> select count(*) from orders group by sales_tax having count(*) > 1
[SELECT_ITEMS=
1,Expr,"COUNT('*')",,UNS INT(4),,C STRING(11)]
[ORDER_BY=NONE]

COUNT('*')  
----------  
         4  
         2  
         2  
         3  
         3  
         2  
         2  
         2  
         6  
         5  
         2  
         8  
         2  
         2  
         3  
         8  
         5  
         3  
         5  
         2  
         4  
         2  
         2  
         2  
         4  
         8  
         3  
         2  
         5  
         3  
         6  
         2  
         2  
         3  
         2  
         3  
         2  
37 rows returned
> ;
> ; non-optimized
> ; <TEST=H2>
> ;103
> select min(cust_since), last_order, contact from prospects \
 (cont) >  where (contact not like 'Clint%') \
 (cont) >  group by last_order, contact having min(cust_since) >= 1997
[SELECT_ITEMS=
1,Expr,"MIN(PROSPECTS.CUST_SINCE)",,ODX DATE(2),YYYY,C STRING(11)
2,Column,STAR_ENV.STAR.PROSPECTS.LAST_ORDER,,ODX DATE(4),YYYYMMDD,C STRING(17)
3,Column,STAR_ENV.STAR.PROSPECTS.CONTACT,,C STRING(24),,C STRING(24)]
[ORDER_BY=NONE]

MIN(PROSPE  LAST_ORDER        CONTACT                  
----------  ----------------  -----------------------  
      1997      Mar 18, 1997  Harriet Gradziel         
      1998      May 13, 1998  Michelle Behrman         
      1998       Aug 5, 1998  Roxanne Dunagan          
      1998       Sep 8, 1998  Anna Fireball            
      1998       Oct 2, 1998  Jack Niehause            
5 rows returned
> ;
> ; not in select list
> ; <TEST=H3>
> ;104
> select max(cust_since), contact from prospects \
 (cont) > where (contact not like 'Clint%') \
 (cont) > group by contact having min(cust_since) >= 1997
[SELECT_ITEMS=
1,Expr,"MAX(PROSPECTS.CUST_SINCE)",,ODX DATE(2),YYYY,C STRING(11)
2,Column,STAR_ENV.STAR.PROSPECTS.CONTACT,,C STRING(24),,C STRING(24)]
[ORDER_BY=NONE]

MAX(PROSPE  CONTACT                  
----------  -----------------------  
      1998  Anna Fireball            
      1997  Harriet Gradziel         
      1998  Jack Niehause            
      1998  Michelle Behrman         
      1998  Roxanne Dunagan          
5 rows returned
> ;
> ; multiple-tbl
> ; <TEST=H4>
> ;105
> select dt, prospects.acct, sum(prospects.cr_limit) \
 (cont) >   from prospects, activity \
 (cont) >  where prospects.acct = activity.acct \
 (cont) >  group by dt, prospects.acct \
 (cont) > having activity.dt > '01-01-1991' and prospects.acct < 10 \
 (cont) >        and min(cr_limit) > 0
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.ACTIVITY.DT,,ODX DATE(4),YYYYMMDD,C STRING(17)
2,Column,STAR_ENV.STAR.PROSPECTS.ACCT,,INT(4),,C STRING(12)
3,Expr,"SUM(PROSPECTS.CR_LIMIT)",,DOUBLE(8),,C STRING(33)]
[ORDER_BY=NONE]

DT                ACCT         SUM(PROSPECTS.CR_LIMIT)           
----------------  -----------  --------------------------------  
     Feb 1, 1994            2                         25.000000  
     May 1, 1994            2                         25.000000  
     Jul 1, 1994            2                         25.000000  
     Nov 1, 1994            2                         25.000000  
     Feb 1, 1995            2                         25.000000  
     Feb 1, 1995            3                         15.000000  
     May 1, 1995            2                         25.000000  
     May 1, 1995            3                         15.000000  
     Jul 1, 1995            2                         25.000000  
     Jul 1, 1995            3                         15.000000  
     Nov 1, 1995            2                         25.000000  
     Nov 1, 1995            3                         15.000000  
    Jan 15, 1996            3                         15.000000  
     Feb 1, 1996            2                         25.000000  
     Feb 1, 1996            3                         15.000000  
     Feb 1, 1996            4                         15.000000  
     May 1, 1996            2                         25.000000  
     May 1, 1996            3                         15.000000  
     May 1, 1996            4                         15.000000  
     Jul 1, 1996            2                         25.000000  
     Jul 1, 1996            3                         15.000000  
     Jul 1, 1996            4                         15.000000  
    Oct 13, 1996            4                         15.000000  
     Nov 1, 1996            2                         25.000000  
     Nov 1, 1996            3                         15.000000  
     Nov 1, 1996            4                         15.000000  
     Feb 1, 1997            2                         25.000000  
     Feb 1, 1997            3                         15.000000  
     Feb 1, 1997            4                         15.000000  
     Feb 1, 1997            6                         30.000000  
     May 1, 1997            2                         25.000000  
     May 1, 1997            3                         15.000000  
     May 1, 1997            4                         15.000000  
     May 1, 1997            6                         30.000000  
     Jul 1, 1997            2                         25.000000  
     Jul 1, 1997            3                         15.000000  
     Jul 1, 1997            4                         15.000000  
     Jul 1, 1997            6                         30.000000  
     Nov 1, 1997            2                         25.000000  
     Nov 1, 1997            3                         15.000000  
     Nov 1, 1997            4                         15.000000  
     Nov 1, 1997            6                         30.000000  
     Dec 3, 1997            2                         25.000000  
     Feb 1, 1998            2                         25.000000  
     Feb 1, 1998            3                         15.000000  
     Feb 1, 1998            4                         15.000000  
     Feb 1, 1998            6                         30.000000  
     Feb 1, 1998            8                         15.000000  
     Feb 1, 1998            9                         45.000000  
     May 1, 1998            2                         25.000000  
     May 1, 1998            3                         15.000000  
     May 1, 1998            4                         15.000000  
     May 1, 1998            6                         30.000000  
     May 1, 1998            8                         15.000000  
54 rows returned
> ;
> ; grp col optimized
> ; <TEST=H5>
> ;106
> select every 10 dt, prospects.acct, sum(prospects.cr_limit) \
 (cont) >   from prospects, activity \
 (cont) >  where prospects.acct = activity.acct \
 (cont) >  group by dt, prospects.acct \
 (cont) > having activity.dt > '01-01-1991' and prospects.acct < 10 \
 (cont) > order by 1, 2, 3
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.ACTIVITY.DT,,ODX DATE(4),YYYYMMDD,C STRING(17)
2,Column,STAR_ENV.STAR.PROSPECTS.ACCT,,INT(4),,C STRING(12)
3,Expr,"SUM(PROSPECTS.CR_LIMIT)",,DOUBLE(8),,C STRING(33)]
[ORDER_BY=EXACT]

DT                ACCT         SUM(PROSPECTS.CR_LIMIT)           
----------------  -----------  --------------------------------  
     May 1, 1993            1                          0.000000  
     Nov 1, 1994            1                          0.000000  
     Jul 1, 1995            2                         25.000000  
     May 1, 1996            1                          0.000000  
     Nov 1, 1996            2                         25.000000  
     May 1, 1997            1                          0.000000  
     Jul 1, 1997            5                          0.000000  
     Feb 1, 1998            2                         25.000000  
     May 1, 1998            3                         15.000000  
9 rows returned
> ; Test reuse
> ; <TEST=H5r>
> ;107
> select every 10 dt, prospects.acct, sum(prospects.cr_limit) \
 (cont) >   from prospects, activity \
 (cont) >  where prospects.acct = activity.acct \
 (cont) >  group by dt, prospects.acct \
 (cont) > having activity.dt > '01-01-1991' and prospects.acct < 10 \
 (cont) > order by 1, 2, 3
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.ACTIVITY.DT,,ODX DATE(4),YYYYMMDD,C STRING(17)
2,Column,STAR_ENV.STAR.PROSPECTS.ACCT,,INT(4),,C STRING(12)
3,Expr,"SUM(PROSPECTS.CR_LIMIT)",,DOUBLE(8),,C STRING(33)]
[ORDER_BY=EXACT]

DT                ACCT         SUM(PROSPECTS.CR_LIMIT)           
----------------  -----------  --------------------------------  
     May 1, 1993            1                          0.000000  
     Nov 1, 1994            1                          0.000000  
     Jul 1, 1995            2                         25.000000  
     May 1, 1996            1                          0.000000  
     Nov 1, 1996            2                         25.000000  
     May 1, 1997            1                          0.000000  
     Jul 1, 1997            5                          0.000000  
     Feb 1, 1998            2                         25.000000  
     May 1, 1998            3                         15.000000  
9 rows returned
> ;
> ; mst-optimized
> ; <TEST=H6>
> ;108
> select min(quantity) from orders \
 (cont) >        having min(quantity) = 1
[SELECT_ITEMS=
1,Expr,"MIN(ORDERS.QUANTITY)",,TINYINT(1),,C STRING(6)]
[ORDER_BY=NONE]

MIN(O  
-----  
    1  
1 row returned
> ; <TEST=H7>
> ;109
> select acct, avg(amount) from orders \
 (cont) >        group by acct \
 (cont) >        having avg(amount) <= 1000 and avg(amount) >= 10
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.ORDERS.ACCT,,INT(4),,C STRING(12)
2,Expr,"AVG(ORDERS.AMOUNT)",,DOUBLE(8),,C STRING(33)]
[ORDER_BY=NONE]

ACCT         AVG(ORDERS.AMOUNT)                
-----------  --------------------------------  
          1                        677.432394  
          2                        696.100000  
2 rows returned
> ;
> ; "having" not in sel list
> ; <TEST=H8>
> ;110
> select discount, sum(total) \
 (cont) >   from orders \
 (cont) >  where pmt_method <= 5 \
 (cont) >  group by discount \
 (cont) > having avg(quantity) > 10
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.ORDERS.DISCOUNT,,TINYINT(1),,C STRING(6)
2,Expr,"SUM(ORDERS.TOTAL)",,DOUBLE(8),,C STRING(33)]
[ORDER_BY=NONE]

DISCO  SUM(ORDERS.TOTAL)                 
-----  --------------------------------  
0 rows returned
> ;
> ; mix, complex
> ; <TEST=H9>
> ;111
> select discount, avg(total) * count(*), min(quantity) mq, max(sales_tax) ms \
 (cont) >   from orders \
 (cont) >  group by discount \
 (cont) > having (sum(amount * quantity) > 100.00 or count(*) < 10) and \
 (cont) >        ms / mq < 100.0
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.ORDERS.DISCOUNT,,TINYINT(1),,C STRING(6)
2,Expr,"AVG(ORDERS.TOTAL) * COUNT('*')",,DOUBLE(8),,C STRING(33)
3,Expr,"MIN(ORDERS.QUANTITY)",MQ,TINYINT(1),,C STRING(6)
4,Expr,"MAX(ORDERS.SALES_TAX)",MS,FLOAT(4),,C STRING(33)]
[ORDER_BY=NONE]

DISCO  AVG(ORDERS.TOTAL) * COUNT('*')    MQ     
-----  --------------------------------  -----  
MS                                
--------------------------------  
    0                          6.000000      1  
                        0.375000  
1 row returned
> ; Test reuse
> ; <TEST=H9r>
> ;112
> select discount, avg(total) * count(*), min(quantity) mq, max(sales_tax) ms \
 (cont) >   from orders \
 (cont) >  group by discount \
 (cont) > having (sum(amount * quantity) > 100.00 or count(*) < 10) and \
 (cont) >        ms / mq < 100.0
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.ORDERS.DISCOUNT,,TINYINT(1),,C STRING(6)
2,Expr,"AVG(ORDERS.TOTAL) * COUNT('*')",,DOUBLE(8),,C STRING(33)
3,Expr,"MIN(ORDERS.QUANTITY)",MQ,TINYINT(1),,C STRING(6)
4,Expr,"MAX(ORDERS.SALES_TAX)",MS,FLOAT(4),,C STRING(33)]
[ORDER_BY=NONE]

DISCO  AVG(ORDERS.TOTAL) * COUNT('*')    MQ     
-----  --------------------------------  -----  
MS                                
--------------------------------  
    0                          6.000000      1  
                        0.375000  
1 row returned
> ; <TEST=H10>
> ;113
> select count(quantity), 100 * $round(avg(total * 0.90), 1), max(wholesale) \
 (cont) >   from orders o, products p \
 (cont) >  where o.product_no = p.product_no and \
 (cont) >         (o.amount < 100 or o.quantity between 5 and 10 \
 (cont) >         or p.description like '%Computer') \
 (cont) >  group by category \
 (cont) > having count(quantity) < 100 or \
 (cont) >        sum(wholesale * quantity) >= sum(amount * quantity) or \
 (cont) >        category not in (1,2,3,8,9,10,21,22,23)
[SELECT_ITEMS=
1,Expr,"COUNT(O.QUANTITY)",,UNS INT(4),,C STRING(11)
2,Expr,"100 * $ROUND(AVG(O.TOTAL * 0.90),1)",,DOUBLE(8),,C STRING(33)
3,Expr,"MAX(P.WHOLESALE)",,FLOAT(4),,C STRING(33)]
[ORDER_BY=NONE]

COUNT(O.QU  100 * $ROUND(AVG(O.TOTAL * 0.90)  
----------  --------------------------------  
MAX(P.WHOLESALE)                  
--------------------------------  
         1                       5620.000000  
                       53.330002  
        58                     739300.000000  
                     1985.709961  
         1                      98280.000000  
                      142.860001  
         2                     339390.000000  
                      821.429993  
        13                      23850.000000  
                       71.430000  
        10                      30080.000000  
                       64.290001  
         1                     443660.000000  
                      564.289978  
         4                       2450.000000  
                       26.920000  
         1                        410.000000  
                        3.850000  
         2                       4130.000000  
                       16.920000  
         4                        390.000000  
                        6.920000  
         2                       6140.000000  
                       75.000000  
         2                        560.000000  
                        6.920000  
         4                        280.000000  
                        5.380000  
         3                       4680.000000  
                       64.620003  
         3                        700.000000  
                        6.920000  
         1                         70.000000  
                        0.770000  
         1                       1620.000000  
                        1.540000  
         5                        850.000000  
                        2.310000  
19 rows returned
> ;
> ; on date
> ; <TEST=H11>
> ;114
> select acct, min(order_date) from orders where pmt_method >= 5 \
 (cont) >  group by acct \
 (cont) > having max(order_date) = '10-20-1996'
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.ORDERS.ACCT,,INT(4),,C STRING(12)
2,Expr,"MIN(ORDERS.ORDER_DATE)",,ODX DATE(4),YYYYMMDD,C STRING(17)]
[ORDER_BY=NONE]

ACCT         MIN(ORDERS.ORDER  
-----------  ----------------  
0 rows returned
> ;
> ;
> ;
> ; <SECTION=ORDER_BY>
> ; (in addition to those tested above)
> ;
> ; <TEST=O1>
> ;115
> select acct from prospects order by acct desc
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.PROSPECTS.ACCT,,INT(4),,C STRING(12)]
[ORDER_BY=EXACT]

ACCT         
-----------  
         10  
          9  
          8  
          7  
          6  
          5  
          4  
          3  
          2  
          1  
10 rows returned
> ; <TEST=O2>
> ;116
> select quantity from orders \
 (cont) >   where discount >= 20 and total > 1000 and not quantity < 15 \
 (cont) >   order by quantity desc
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.ORDERS.QUANTITY,,TINYINT(1),,C STRING(6)]
[ORDER_BY=1]

QUANT  
-----  
   20  
   19  
   19  
   19  
   19  
   18  
   18  
   18  
   18  
   17  
   15  
   15  
12 rows returned
> ; <TEST=O3>
> ;117
> select quantity from orders \
 (cont) >   where discount >= 20 and total > 1000 and not quantity < 15 \
 (cont) >   order by order_date desc
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.ORDERS.QUANTITY,,TINYINT(1),,C STRING(6)]
[ORDER_BY=UNVERIFIABLE]

QUANT  
-----  
   19  
   18  
   18  
   19  
   19  
   15  
   19  
   15  
   20  
   18  
   17  
   18  
12 rows returned
> ; <TEST=O4>
> ;118
> select pmt_method, discount, quantity, amount from orders \
 (cont) >   where total > 1000 \
 (cont) >  order by 2 desc, 1, 4 desc
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.ORDERS.PMT_METHOD,,TINYINT(1),,C STRING(6)
2,Column,STAR_ENV.STAR.ORDERS.DISCOUNT,,TINYINT(1),,C STRING(6)
3,Column,STAR_ENV.STAR.ORDERS.QUANTITY,,TINYINT(1),,C STRING(6)
4,Column,STAR_ENV.STAR.ORDERS.AMOUNT,,FLOAT(4),,C STRING(33)]
[ORDER_BY=2,1,4]

PMT_M  DISCO  QUANT  AMOUNT                            
-----  -----  -----  --------------------------------  
    1     22      1                       1872.000000  
    1     22      1                       1857.180054  
    1     22      8                        616.200012  
    1     22     20                        312.000000  
    1     22      7                        156.000000  
    2     22      1                       2067.000000  
    2     22      1                       1829.880005  
    2     22      1                       1829.880005  
    2     22     19                       1755.000000  
    2     22      1                       1638.000000  
    2     22     15                        152.100006  
    3     22     10                       2168.399902  
    3     22      1                       1904.760010  
    3     22      1                       1857.180054  
    3     22      1                       1857.180054  
    3     22      1                       1833.000000  
    3     22      1                       1833.000000  
    3     22      1                       1829.880005  
    3     22     11                       1829.880005  
    3     22     19                       1638.000000  
    3     22     13                        249.600006  
    4     22      1                       1857.180054  
    4     22      1                       1833.000000  
    4     22      1                       1829.880005  
    4     22      1                       1638.000000  
    5     22      3                       1700.400024  
    6     22      1                       2168.399902  
    6     22      1                       2067.000000  
    6     22      1                       1872.000000  
    6     22      7                       1833.000000  
    6     22     13                       1829.880005  
    6     22      1                       1700.400024  
    6     22      1                       1638.000000  
    6     22      6                        897.000000  
    6     22     18                        195.000000  
    6     22     15                        156.000000  
    6     22     13                        156.000000  
    7     22     14                       2168.399902  
    7     22     19                       1904.760010  
    7     22      1                       1755.000000  
    7     22      1                       1638.000000  
    7     22      1                       1638.000000  
    8     22      1                       2067.000000  
    8     22      1                       1700.400024  
    8     22      1                       1638.000000  
    8     22      1                       1638.000000  
    8     22     12                       1638.000000  
    8     22     18                        897.000000  
    8     22     18                        312.000000  
    8     22     13                        312.000000  
    8     22     11                        234.000000  
    9     22      1                       2168.399902  
    9     22      1                       1904.760010  
    9     22      1                       1755.000000  
    9     22     11                       1638.000000  
    9     22     13                        897.000000  
    9     22     19                        195.000000  
   10     22      3                       1857.180054  
   10     22      1                       1857.180054  
   10     22      1                       1857.180054  
   10     22      1                       1829.880005  
   10     22      1                       1700.400024  
   10     22      1                       1638.000000  
   10     22     18                        163.800003  
   10     22     17                        132.600006  
    1     10     16                       2160.000000  
    3     10      1                       1890.000000  
    5     10     13                       2160.000000  
    5     10      6                       2115.000000  
    6     10     18                       1890.000000  
    6     10      1                       1890.000000  
    7     10      1                       2160.000000  
    7     10      1                       2025.000000  
    8     10     16                       2115.000000  
    8     10      1                       1890.000000  
    9     10      6                        360.000000  
76 rows returned
> ; Test reuse
> ; <TEST=O4r>
> ;119
> select pmt_method, discount, quantity, amount from orders \
 (cont) >   where total > 1000 \
 (cont) >  order by 2 desc, 1, 4 desc
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.ORDERS.PMT_METHOD,,TINYINT(1),,C STRING(6)
2,Column,STAR_ENV.STAR.ORDERS.DISCOUNT,,TINYINT(1),,C STRING(6)
3,Column,STAR_ENV.STAR.ORDERS.QUANTITY,,TINYINT(1),,C STRING(6)
4,Column,STAR_ENV.STAR.ORDERS.AMOUNT,,FLOAT(4),,C STRING(33)]
[ORDER_BY=2,1,4]

PMT_M  DISCO  QUANT  AMOUNT                            
-----  -----  -----  --------------------------------  
    1     22      1                       1872.000000  
    1     22      1                       1857.180054  
    1     22      8                        616.200012  
    1     22     20                        312.000000  
    1     22      7                        156.000000  
    2     22      1                       2067.000000  
    2     22      1                       1829.880005  
    2     22      1                       1829.880005  
    2     22     19                       1755.000000  
    2     22      1                       1638.000000  
    2     22     15                        152.100006  
    3     22     10                       2168.399902  
    3     22      1                       1904.760010  
    3     22      1                       1857.180054  
    3     22      1                       1857.180054  
    3     22      1                       1833.000000  
    3     22      1                       1833.000000  
    3     22      1                       1829.880005  
    3     22     11                       1829.880005  
    3     22     19                       1638.000000  
    3     22     13                        249.600006  
    4     22      1                       1857.180054  
    4     22      1                       1833.000000  
    4     22      1                       1829.880005  
    4     22      1                       1638.000000  
    5     22      3                       1700.400024  
    6     22      1                       2168.399902  
    6     22      1                       2067.000000  
    6     22      1                       1872.000000  
    6     22      7                       1833.000000  
    6     22     13                       1829.880005  
    6     22      1                       1700.400024  
    6     22      1                       1638.000000  
    6     22      6                        897.000000  
    6     22     18                        195.000000  
    6     22     15                        156.000000  
    6     22     13                        156.000000  
    7     22     14                       2168.399902  
    7     22     19                       1904.760010  
    7     22      1                       1755.000000  
    7     22      1                       1638.000000  
    7     22      1                       1638.000000  
    8     22      1                       2067.000000  
    8     22      1                       1700.400024  
    8     22      1                       1638.000000  
    8     22      1                       1638.000000  
    8     22     12                       1638.000000  
    8     22     18                        897.000000  
    8     22     18                        312.000000  
    8     22     13                        312.000000  
    8     22     11                        234.000000  
    9     22      1                       2168.399902  
    9     22      1                       1904.760010  
    9     22      1                       1755.000000  
    9     22     11                       1638.000000  
    9     22     13                        897.000000  
    9     22     19                        195.000000  
   10     22      3                       1857.180054  
   10     22      1                       1857.180054  
   10     22      1                       1857.180054  
   10     22      1                       1829.880005  
   10     22      1                       1700.400024  
   10     22      1                       1638.000000  
   10     22     18                        163.800003  
   10     22     17                        132.600006  
    1     10     16                       2160.000000  
    3     10      1                       1890.000000  
    5     10     13                       2160.000000  
    5     10      6                       2115.000000  
    6     10     18                       1890.000000  
    6     10      1                       1890.000000  
    7     10      1                       2160.000000  
    7     10      1                       2025.000000  
    8     10     16                       2115.000000  
    8     10      1                       1890.000000  
    9     10      6                        360.000000  
76 rows returned
> ; <TEST=O5>
> ;120
> select top 10 * from activity \
 (cont) >   where dt >= '01-01-1996' and initials != 'EFR' \
 (cont) >   order by initials desc, tickler desc, dt, acct
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.ACTIVITY.ACCT,,INT(4),,C STRING(12)
2,Column,STAR_ENV.STAR.ACTIVITY.DT,,ODX DATE(4),YYYYMMDD,C STRING(17)
3,Column,STAR_ENV.STAR.ACTIVITY.TICKLER,,CHAR(2),,CHAR(2)
4,Column,STAR_ENV.STAR.ACTIVITY.INITIALS,,CHAR(4),,CHAR(4)]
[ORDER_BY=4,3,2,1]

ACCT         DT                TI  INIT  
-----------  ----------------  --  ----  
          3      Jan 15, 1996  MF  SHIP  
          1      Mar 15, 1997  MF  SHIP  
          1       Nov 1, 1996  C4  SHIP  
          2       Nov 1, 1996  C4  SHIP  
          3       Nov 1, 1996  C4  SHIP  
          4       Nov 1, 1996  C4  SHIP  
          1       Nov 1, 1997  C4  SHIP  
          2       Nov 1, 1997  C4  SHIP  
          3       Nov 1, 1997  C4  SHIP  
          4       Nov 1, 1997  C4  SHIP  
10 rows returned
> ; <TEST=O6>
> ;121
> select product_no, acct, min(total) from orders \
 (cont) >   group by acct, product_no \
 (cont) >   order by product_no, acct
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.ORDERS.PRODUCT_NO,,CHAR(4),,CHAR(4)
2,Column,STAR_ENV.STAR.ORDERS.ACCT,,INT(4),,C STRING(12)
3,Expr,"MIN(ORDERS.TOTAL)",,FLOAT(4),,C STRING(33)]
[ORDER_BY=1,2]

PROD  ACCT         MIN(ORDERS.TOTAL)                 
----  -----------  --------------------------------  
3DST            1                          2.340000  
3MTP            1                          0.780000  
3MTP            2                          0.900000  
3P23            1                          4.680000  
3RGS            1                          9.360000  
3SAD            1                          7.020000  
A940            1                       1638.000000  
A940            2                       1890.000000  
AAWP            1                          3.120000  
ACPC            1                          0.780000  
ADLB            2                          4.500000  
AEWP            2                          8.100000  
AQPP            1                          1.560000  
B190            1                        156.000000  
B190            2                        180.000000  
B290            1                        195.000000  
B290            2                        225.000000  
B390            1                        234.000000  
B455            1                        616.200012  
BMED            1                        312.000000  
BMLF            2                        270.000000  
BRSP            1                          0.780000  
BTCT            1                         24.959999  
C478            1                       2067.000000  
CGPP            1                         42.900002  
DM20            1                       1857.180054  
DM23            1                       1904.760010  
EDMP            1                        312.000000  
G520            1                       1638.000000  
G520            2                       1890.000000  
G523            1                       1829.880005  
GEHE            1                        179.399994  
GEHE            2                        207.000000  
GTLC            2                        234.000000  
GUOC            1                       2340.000000  
H100            1                        390.000000  
H100            2                        450.000000  
H400            1                        897.000000  
H672            1                        156.000000  
H672            2                        180.000000  
H736            1                       1755.000000  
H736            2                       2025.000000  
HL6P            1                        312.000000  
HL6P            2                        360.000000  
HLTC            1                         65.519997  
HO30            1                        358.799988  
HPMP            1                         27.299999  
HPMP            2                         31.500000  
IC9S            1                       1833.000000  
IC9S            2                      12690.000000  
L433            1                        741.000000  
L433            2                        360.000000  
L722            1                         78.000000  
L722            2                         90.000000  
MMRB            1                         93.599998  
MPOP            1                         70.199997  
MPOP            2                        972.000000  
MTAC            1                        249.600006  
N820            1                         22.620001  
N972            1                       2168.399902  
OSER            1                        163.800003  
OSTC            1                        140.399994  
P160            1                         39.000000  
P224            1                       1700.400024  
P225            1                       1872.000000  
P225            2                       2160.000000  
P900            1                        132.600006  
PBSP            1                          5.460000  
PDMP            1                          7.020000  
PGMP            2                          5.400000  
PH65            1                        152.100006  
PH65            2                        175.500000  
S100            1                        156.000000  
S25P            3                          6.000000  
SCDR            1                         62.400002  
SCFP            1                         85.800003  
SSST            2                         18.000000  
SWFL            2                        144.000000  
T750            1                         70.199997  
XPCP            1                         22.620001  
80 rows returned
> ; see 'where clause' tests for order-by testing on multiple tables
> ; Test reuse
> ; <TEST=O6r>
> ;122
> select product_no, acct, min(total) from orders \
 (cont) >   group by acct, product_no \
 (cont) >   order by product_no, acct
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.ORDERS.PRODUCT_NO,,CHAR(4),,CHAR(4)
2,Column,STAR_ENV.STAR.ORDERS.ACCT,,INT(4),,C STRING(12)
3,Expr,"MIN(ORDERS.TOTAL)",,FLOAT(4),,C STRING(33)]
[ORDER_BY=1,2]

PROD  ACCT         MIN(ORDERS.TOTAL)                 
----  -----------  --------------------------------  
3DST            1                          2.340000  
3MTP            1                          0.780000  
3MTP            2                          0.900000  
3P23            1                          4.680000  
3RGS            1                          9.360000  
3SAD            1                          7.020000  
A940            1                       1638.000000  
A940            2                       1890.000000  
AAWP            1                          3.120000  
ACPC            1                          0.780000  
ADLB            2                          4.500000  
AEWP            2                          8.100000  
AQPP            1                          1.560000  
B190            1                        156.000000  
B190            2                        180.000000  
B290            1                        195.000000  
B290            2                        225.000000  
B390            1                        234.000000  
B455            1                        616.200012  
BMED            1                        312.000000  
BMLF            2                        270.000000  
BRSP            1                          0.780000  
BTCT            1                         24.959999  
C478            1                       2067.000000  
CGPP            1                         42.900002  
DM20            1                       1857.180054  
DM23            1                       1904.760010  
EDMP            1                        312.000000  
G520            1                       1638.000000  
G520            2                       1890.000000  
G523            1                       1829.880005  
GEHE            1                        179.399994  
GEHE            2                        207.000000  
GTLC            2                        234.000000  
GUOC            1                       2340.000000  
H100            1                        390.000000  
H100            2                        450.000000  
H400            1                        897.000000  
H672            1                        156.000000  
H672            2                        180.000000  
H736            1                       1755.000000  
H736            2                       2025.000000  
HL6P            1                        312.000000  
HL6P            2                        360.000000  
HLTC            1                         65.519997  
HO30            1                        358.799988  
HPMP            1                         27.299999  
HPMP            2                         31.500000  
IC9S            1                       1833.000000  
IC9S            2                      12690.000000  
L433            1                        741.000000  
L433            2                        360.000000  
L722            1                         78.000000  
L722            2                         90.000000  
MMRB            1                         93.599998  
MPOP            1                         70.199997  
MPOP            2                        972.000000  
MTAC            1                        249.600006  
N820            1                         22.620001  
N972            1                       2168.399902  
OSER            1                        163.800003  
OSTC            1                        140.399994  
P160            1                         39.000000  
P224            1                       1700.400024  
P225            1                       1872.000000  
P225            2                       2160.000000  
P900            1                        132.600006  
PBSP            1                          5.460000  
PDMP            1                          7.020000  
PGMP            2                          5.400000  
PH65            1                        152.100006  
PH65            2                        175.500000  
S100            1                        156.000000  
S25P            3                          6.000000  
SCDR            1                         62.400002  
SCFP            1                         85.800003  
SSST            2                         18.000000  
SWFL            2                        144.000000  
T750            1                         70.199997  
XPCP            1                         22.620001  
80 rows returned
> ;
> ;
> ; Test 'order by' optimized by imsam
> ;
> ; <TEST=OI1>
> ;123
> select last_order from prospects \
 (cont) >        where last_order > '01-01-1990' \
 (cont) >        order by last_order
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.PROSPECTS.LAST_ORDER,,ODX DATE(4),YYYYMMDD,C STRING(17)]
[ORDER_BY=1]

LAST_ORDER        
----------------  
     Feb 8, 1995  
    Jun 23, 1996  
     Mar 7, 1997  
    Mar 18, 1997  
     Mar 2, 1998  
    May 13, 1998  
     Aug 5, 1998  
     Sep 8, 1998  
     Oct 2, 1998  
     Jan 3, 2002  
10 rows returned
> ; <TEST=OI2>
> ;124
> select profession from prospects \
 (cont) >        where profession > 1 \
 (cont) >        order by profession
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.PROSPECTS.PROFESSION,,TINYINT(1),,C STRING(6)]
[ORDER_BY=1]

PROFE  
-----  
    2  
    3  
    4  
    6  
    7  
    8  
    9  
    9  
   10  
9 rows returned
> ;
> ;
> ;
> ; <SECTION=STARSCHEMA_SCENARIOS>
> ; (may or may not use starschema opt)
> ;
> ; <TEST=SS1>
> ;125
> select p.contact, sum(o.total) from prospects p, orders o \
 (cont) >        where o.acct = p.acct \
 (cont) >        group by p.contact
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.P.CONTACT,,C STRING(24),,C STRING(24)
2,Expr,"SUM(O.TOTAL)",,DOUBLE(8),,C STRING(33)]
[ORDER_BY=NONE]

CONTACT                  SUM(O.TOTAL)                      
-----------------------  --------------------------------  
Joanne Meyer                                161371.800000  
Mark Trasko                                 426175.619165  
Marty Kincaid                                    6.000000  
3 rows returned
> ; <TEST=SS2>
> ;126
> select r.description, avg(o.amount), min(o.total) from products r, orders o \
 (cont) >        where r.product_no = o.product_no and \
 (cont) >         (o.quantity >= 10 and r.wholesale > 1000.00) \
 (cont) >        group by r.description
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.R.DESCRIPTION,,C STRING(32),,C STRING(32)
2,Expr,"AVG(O.AMOUNT)",,DOUBLE(8),,C STRING(33)
3,Expr,"MIN(O.TOTAL)",,FLOAT(4),,C STRING(33)]
[ORDER_BY=NONE]

DESCRIPTION                      AVG(O.AMOUNT)                     
-------------------------------  --------------------------------  
MIN(O.TOTAL)                      
--------------------------------  
2000 G5-233 Computer                                  1829.880005  
                    20128.679688  
Advantage 9404 Computer                               1764.000000  
                    19656.000000  
Aptiva C9S Computer                                   2115.000000  
                    33840.000000  
Dimension XPS M233 Computer                           1904.760010  
                    36190.441406  
G5-200M Computer                                      1638.000000  
                    18018.000000  
Pavillion 7360 Computer                               1755.000000  
                    33345.000000  
Platinum 2250X Computer                               2160.000000  
                    28080.000000  
Ready Systems 9725 Computer                           2168.399902  
                    21684.000000  
8 rows returned
> ; Test reuse
> ; <TEST=SS2r>
> ;127
> select r.description, avg(o.amount), min(o.total) from products r, orders o \
 (cont) >        where r.product_no = o.product_no and \
 (cont) >         (o.quantity >= 10 and r.wholesale > 1000.00) \
 (cont) >        group by r.description
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.R.DESCRIPTION,,C STRING(32),,C STRING(32)
2,Expr,"AVG(O.AMOUNT)",,DOUBLE(8),,C STRING(33)
3,Expr,"MIN(O.TOTAL)",,FLOAT(4),,C STRING(33)]
[ORDER_BY=NONE]

DESCRIPTION                      AVG(O.AMOUNT)                     
-------------------------------  --------------------------------  
MIN(O.TOTAL)                      
--------------------------------  
2000 G5-233 Computer                                  1829.880005  
                    20128.679688  
Advantage 9404 Computer                               1764.000000  
                    19656.000000  
Aptiva C9S Computer                                   2115.000000  
                    33840.000000  
Dimension XPS M233 Computer                           1904.760010  
                    36190.441406  
G5-200M Computer                                      1638.000000  
                    18018.000000  
Pavillion 7360 Computer                               1755.000000  
                    33345.000000  
Platinum 2250X Computer                               2160.000000  
                    28080.000000  
Ready Systems 9725 Computer                           2168.399902  
                    21684.000000  
8 rows returned
> ; <TEST=SS3>
> ;128
> select p.company, r.division, count(o.amount), sum(o.amount) \
 (cont) >        from orders o, prospects p, products r \
 (cont) >        where p.acct = o.acct and o.product_no = r.product_no \
 (cont) >        group by r.division, p.company \
 (cont) >        having count(o.amount) > 10 and sum(o.amount) > 500.00
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.P.COMPANY,,C STRING(60),,C STRING(60)
2,Column,STAR_ENV.STAR.R.DIVISION,,TINYINT(1),,C STRING(6)
3,Expr,"COUNT(O.AMOUNT)",,UNS INT(4),,C STRING(11)
4,Expr,"SUM(O.AMOUNT)",,DOUBLE(8),,C STRING(33)]
[ORDER_BY=NONE]

COMPANY                                                      DIVIS  
-----------------------------------------------------------  -----  
COUNT(O.AM  SUM(O.AMOUNT)                     
----------  --------------------------------  
Dynamic Information Systems Corporation                          2  
        74                      97893.900146  
Sanus/New York Life Health Plan                                  2  
        18                      23175.000000  
Dynamic Information Systems Corporation                          3  
        57                      10749.180046  
3 rows returned
> ; <TEST=SS4>
> ;129
> select avg(amount), avg(total), count(*) \
 (cont) >        from orders o, dates d, products r, prospects p \
 (cont) >        where o.order_date = d.dt and o.product_no = r.product_no and \
 (cont) >              p.acct = o.acct and \
 (cont) >        p.discount_rt != 0 and (r.description like '%Computer%' or quantity > 50) \
 (cont) >        group by d.yr, r.category \
 (cont) >        having count(*) > 2.0  \
 (cont) >        order by 3 desc, 1 asc
[SELECT_ITEMS=
1,Expr,"AVG(O.AMOUNT)",,DOUBLE(8),,C STRING(33)
2,Expr,"AVG(O.TOTAL)",,DOUBLE(8),,C STRING(33)
3,Expr,"COUNT('*')",,UNS INT(4),,C STRING(11)]
[ORDER_BY=3,1]

AVG(O.AMOUNT)                     AVG(O.TOTAL)                      
--------------------------------  --------------------------------  
COUNT('*')  
----------  
                     1939.760010                      10538.150126  
        12  
                     1870.510909                       7259.743430  
        11  
                     1888.127991                       8273.627991  
        10  
                     1814.453342                       2192.320028  
         9  
                     1802.134295                       8929.105678  
         7  
                     1814.837141                      10313.717076  
         7  
6 rows returned
> ; <TEST=SS5>
> ;130
> select o.status, r.dept, avg(o.amount), avg(o.quantity * 1.0) \
 (cont) >        from prospects p, orders o, products r \
 (cont) >        where o.acct = p.acct and o.product_no = r.product_no and  \
 (cont) >        p.state = 'CO' and o.total > 1000.00 and o.source between 1 and 4 \
 (cont) >        and r.cost between 1000.00 and 50000.00 \
 (cont) >        group by o.status, r.dept
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.O.STATUS,,CHAR(2),,CHAR(2)
2,Column,STAR_ENV.STAR.R.DEPT,,SMALLINT(2),,C STRING(8)
3,Expr,"AVG(O.AMOUNT)",,DOUBLE(8),,C STRING(33)
4,Expr,"AVG(O.QUANTITY * 1.0)",,DOUBLE(8),,C STRING(33)]
[ORDER_BY=NONE]

ST  DEPT     AVG(O.AMOUNT)                     
--  -------  --------------------------------  
AVG(O.QUANTITY * 1.0)             
--------------------------------  
CN        3                       1755.000000  
                        1.000000  
SH        3                       1792.027057  
                        4.647059  
2 rows returned
> ;
> ;
> ; <SECTION=SNOWFLAKE_SCENARIOS>
> ;
> ;no special optimization performed (besides where/imslink)
> ; <TEST=SF1>
> ;131
> select d.yr, ca.description, avg(amount), avg(total) \
 (cont) >        from orders o, dates d, products r, categories ca \
 (cont) >        where o.order_date = d.dt and o.product_no = r.product_no and  \
 (cont) >        ca.category = r.category and \
 (cont) >        discount != 0 and (r.description like '%Computer%' or quantity > 50) \
 (cont) >        group by d.yr, ca.description \
 (cont) >        having count(*) > 2.0  \
 (cont) >        order by 3 desc, 1 asc
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.D.YR,,ODX DATE(2),YYYY,C STRING(11)
2,Column,STAR_ENV.STAR.CA.DESCRIPTION,,C STRING(32),,C STRING(32)
3,Expr,"AVG(O.AMOUNT)",,DOUBLE(8),,C STRING(33)
4,Expr,"AVG(O.TOTAL)",,DOUBLE(8),,C STRING(33)]
[ORDER_BY=3,1]

YR          DESCRIPTION                      AVG(O.AMOUNT)                     
----------  -------------------------------  --------------------------------  
AVG(O.TOTAL)                      
--------------------------------  
      1994  Desktop Computer                                      1939.760010  
                    10538.150126  
      1995  Desktop Computer                                      1888.127991  
                     8273.627991  
      1990  Desktop Computer                                      1870.510909  
                     7259.743430  
      1992  Desktop Computer                                      1814.837141  
                    10313.717076  
      1991  Desktop Computer                                      1814.453342  
                     2192.320028  
      1993  Desktop Computer                                      1802.134295  
                     8929.105678  
6 rows returned
> ; <TEST=SF2>
> ;132
> select sum(o.total), min(o.order_date) \
 (cont) >   from orders o, products p, divisions d, depts e \
 (cont) >   where (p.division = d.division and p.dept = e.dept and o.product_no = p.product_no) and \
 (cont) >         (d.description = 'Furniture' or e.description in ('Desks', 'Chairs'))
[SELECT_ITEMS=
1,Expr,"SUM(O.TOTAL)",,DOUBLE(8),,C STRING(33)
2,Expr,"MIN(O.ORDER_DATE)",,ODX DATE(4),YYYYMMDD,C STRING(17)]
[ORDER_BY=NONE]

SUM(O.TOTAL)                      MIN(O.ORDER_DATE  
--------------------------------  ----------------  
                     7165.200142      Dec 20, 1990  
1 row returned
> ; <TEST=SF3>
> ;133
> select s.description, di.description, max(o.discount), \
 (cont) >         count(distinct o.discount) numdiscounts \
 (cont) >   from orders o, products r, dates d, statuses s, divisions di \
 (cont) >   where (o.product_no = r.product_no and o.order_date = d.dt \
 (cont) >         and o.status = s.status and r.division = di.division) and \
 (cont) >         (s.description = 'Cancelled' or d.yr < 1991 \
 (cont) >         or o.discount = 0 or r.margin <= 30) \
 (cont) >         group by s.description, di.description \
 (cont) >         having numdiscounts > 1 order by 2, 1 desc
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.S.DESCRIPTION,,C STRING(32),,C STRING(32)
2,Column,STAR_ENV.STAR.DI.DESCRIPTION,,C STRING(32),,C STRING(32)
3,Expr,"MAX(O.DISCOUNT)",,TINYINT(1),,C STRING(6)
4,Expr,"COUNT(DISTINCT O.DISCOUNT)",NUMDISCOUNTS,UNS INT(4),,C STRING(11)]
[ORDER_BY=2,1]

DESCRIPTION                      DESCRIPTION                      MAX(O  
-------------------------------  -------------------------------  -----  
NUMDISCOUN  
----------  
Shipped                          Office Supplies                     22  
         2  
Shipped                          Paper Products                      22  
         3  
2 rows returned
> ; <TEST=SF4>
> ;134
> select d.description, $round(sum(o.amount * r.wholesale) * 100) \
 (cont) >   from orders o, products r, divisions d \
 (cont) >   where r.division = d.division and o.product_no = r.product_no \
 (cont) >   group by d.description
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.D.DESCRIPTION,,C STRING(32),,C STRING(32)
2,Expr,"$ROUND(SUM(O.AMOUNT * R.WHOLESALE) * 100)",,DOUBLE(8),,C STRING(33)]
[ORDER_BY=NONE]

DESCRIPTION                      $ROUND(SUM(O.AMOUNT * R.WHOLESAL  
-------------------------------  --------------------------------  
Communications Equipment                         333514004.000000  
Computer Equipment                             18634977663.000000  
Furniture                                         36213873.000000  
Office Supplies                                    1782463.000000  
Paper Products                                      324754.000000  
5 rows returned
> ; <TEST=SF5>
> ;135
> select g.description, d.description, avg(o.total) \
 (cont) >   from orders o, products r, depts d, prospects p, genders g \
 (cont) >   where r.dept = d.dept and o.product_no = r.product_no and \
 (cont) >        p.acct = o.acct and p.gender = g.gender and \
 (cont) >        d.description in ('Computers', 'Printers', 'Fax Machines', 'Telephones') \
 (cont) >   group by g.description, d.description
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.G.DESCRIPTION,,C STRING(32),,C STRING(32)
2,Column,STAR_ENV.STAR.D.DESCRIPTION,,C STRING(32),,C STRING(32)
3,Expr,"AVG(O.TOTAL)",,DOUBLE(8),,C STRING(33)]
[ORDER_BY=NONE]

DESCRIPTION                      DESCRIPTION                      
-------------------------------  -------------------------------  
AVG(O.TOTAL)                      
--------------------------------  
Female                           Computers                        
                    15304.500000  
Female                           Fax Machines                     
                      375.000000  
Female                           Printers                         
                      585.000000  
Female                           Telephones                       
                      399.375000  
Male                             Computers                        
                     6737.331223  
Male                             Fax Machines                     
                     1007.685718  
Male                             Printers                         
                     2206.500000  
Male                             Telephones                       
                      483.036674  
8 rows returned
> ;
> ;
> ; <SECTION=SELECT_INTO>
> ;
> ;TABLE TYPE1 - checking for select into, select from the table created.
> ;The drop is performed after the pseudocolumns test.
> ;
> ;select into a temp table
> ; <TEST=SI1>
> ;136
> select top 15 p.acct, o.acct as o_acct, sum(o.acct) as sum_acct, o.product_no, o.total, o.tax_state \
 (cont) >    into op_temp \
 (cont) >    from orders o join prospects p using (acct) \
 (cont) >    group by p.acct, o_acct, o.product_no, o.total, o.tax_state \
 (cont) >    order by o.product_no desc
15 rows inserted into OP_TEMP
> ;
> ;select from it
> ; <TEST=SI2>
> ;137
> select o_acct, sum_acct \
 (cont) >    from op_temp \
 (cont) >    where tax_state not in ('CA') \
 (cont) >    order by 2
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.OP_TEMP.O_ACCT,,INT(4),,C STRING(12)
2,Column,STAR_ENV.STAR.OP_TEMP.SUM_ACCT,,DOUBLE(8),,C STRING(33)]
[ORDER_BY=2]

O_ACCT       SUM_ACCT                          
-----------  --------------------------------  
          1                          1.000000  
          1                          1.000000  
          1                          1.000000  
          1                          1.000000  
          1                          1.000000  
          1                          1.000000  
          1                          1.000000  
          2                          2.000000  
          2                          2.000000  
          2                          2.000000  
          2                          2.000000  
          1                          2.000000  
          1                          3.000000  
          3                          3.000000  
          1                          4.000000  
15 rows returned
> ;
> ;TABLE TYPE2 - checking for select into, select from.
> ;The drop is performed after the pseudocolumns test, so that the table will be released.
> ;
> ;select into a $tempdb table
> ; <TEST=SI3>
> ;138
> select distinct p.*, o.* \
 (cont) >    into $tempdb.op_temp2 physical "op_temp2.dat" \
 (cont) >    from orders o join prospects p on o.acct = p.acct \
 (cont) >    where o.total > 10.00 or o.amount < 500.00
200 rows inserted into OP_TEMP2
> ;
> ;select from it
> ; <TEST=SI4>
> ;139
> select distinct op.acct1 from $tempdb.op_temp2 op \
 (cont) >    join products p on op.product_no = p.product_no \
 (cont) >    where p.product_no > 'D'
[SELECT_ITEMS=
1,Column,STAR_ENV.$TEMPDB.OP.ACCT1,,INT(4),,C STRING(12)]
[ORDER_BY=NONE]

ACCT1        
-----------  
          1  
          2  
          3  
3 rows returned
> ;
> ; <SECTION=DROP_TABLES>
> ;
> ;Drop tables from the select into's above
> ; <TEST=DT1>
> ;140
> drop table $tempdb.op_temp2
Table OP_TEMP2 dropped
> ; <TEST=DT2>
> ;141
> drop table op_temp
Table OP_TEMP dropped
> ;
> ; <SECTION=PSEUDOCOLUMNS>
> ; <TEST=PC1>
> ;142
> select count(*), avg(distinct p.discount_rt) \
 (cont) >   from products p join orders o using (product_no) \
 (cont) >   where p.discount_rt > 70 or o.acct > 2 \
 (cont) >   group by p.discount_rt \
 (cont) >   order by 2
[SELECT_ITEMS=
1,Expr,"COUNT('*')",,UNS INT(4),,C STRING(11)
2,Expr,"AVG(DISTINCT P.DISCOUNT_RT)",,DOUBLE(8),,C STRING(33)]
[ORDER_BY=2]

COUNT('*')  AVG(DISTINCT P.DISCOUNT_RT)       
----------  --------------------------------  
         4                         71.413788  
         5                         71.419998  
        11                         71.427498  
        14                         71.428001  
         2                         71.428131  
         5                         71.428261  
        14                         71.428391  
         4                         71.428413  
         8                         71.428444  
         6                         71.428505  
        15                         71.428574  
         3                         71.428680  
         5                         71.428696  
         8                         71.428749  
         5                         71.429108  
         7                         71.429413  
        25                         71.430000  
         4                         71.430763  
        11                         71.433334  
         2                         76.857147  
         4                         76.888893  
         1                         76.909088  
         3                         76.914284  
         2                         76.928574  
         1                         76.931030  
         1                         76.937500  
        16                         77.000000  
27 rows returned
> ;
> ; <SECTION=FUNCTIONS>
> ; <TEST=F1>
> ;144
> select company, $soundex(company) sndx, $mod(income, acct) \
 (cont) >    from prospects \
 (cont) >    where $soundex(contact) not in ($soundex('John Moore'), $soundex('Mary Kate Rosak')) \
 (cont) >    order by sndx
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.PROSPECTS.COMPANY,,C STRING(60),,C STRING(60)
2,Expr,"$SOUNDEX(PROSPECTS.COMPANY)",SNDX,C STRING(25),,C STRING(25)
3,Expr,"$MOD(PROSPECTS.INCOME,PROSPECTS.ACCT)",,INT(4),,C STRING(12)]
[ORDER_BY=2]

COMPANY                                                      
-----------------------------------------------------------  
SNDX                      $MOD(PROSPE  
------------------------  -----------  
Data Dimensions                                              
DTDMNSNS                            1  
Frankulin Tool & Mfg. Company, Inc.                          
FRNKLNTLMFGKMPNNK                   2  
GlenAir  Corporation                                         
GLNRKRPRTN                          2  
Maenner Relocation                                           
MNRRLKTN                            1  
Medtronic Cardiocare                                         
MTRNKKRDKR                          5  
Productive Systems                                           
PRDKTFSSTMS                         2  
Smith Information Management Systems                         
SMTNFRMTNMNGMNTSSTMS                8  
Strategic Systems Group                                      
STRTGKSSTMSGRP                      1  
8 rows returned
> ;
> ; <TEST=F2>
> ;145
> select *, $current_row from mfrs \
 (cont) >   where $soundex(description) = $soundex('Smeed') or \
 (cont) >         $soundex(description) = $soundex('Xerox') \
 (cont) >   order by mfr
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.MFRS.MFR,,TINYINT(1),,C STRING(6)
2,Column,STAR_ENV.STAR.MFRS.DESCRIPTION,,C STRING(32),,C STRING(32)
3,Expr,"$CURRENT_ROW",,UNS INT(4),,C STRING(11)]
[ORDER_BY=EXACT]

MFR    DESCRIPTION                      $CURRENT_R  
-----  -------------------------------  ----------  
   13  Smead                                     1  
   18  Xerox                                     2  
2 rows returned
> ;
> ;
> ; <SECTION=PROBLEM_QUERIES>
> ;   The next 3 are problems that pop up from time to time:
> ; <TEST=PRBQ1>
> ;146
> select acct, order_date, quantity, total from orders \
 (cont) >   where ((order_date between '01-01-1996' and '12-31-1996' and quantity > 10) or \
 (cont) >   (order_date between '01-01-1995'and '12-31-1995' \
 (cont) >   and (quantity > 200 or total > 1000000))) and tax_state = 'CO'
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.ORDERS.ACCT,,INT(4),,C STRING(12)
2,Column,STAR_ENV.STAR.ORDERS.ORDER_DATE,,ODX DATE(4),YYYYMMDD,C STRING(17)
3,Column,STAR_ENV.STAR.ORDERS.QUANTITY,,TINYINT(1),,C STRING(6)
4,Column,STAR_ENV.STAR.ORDERS.TOTAL,,FLOAT(4),,C STRING(33)]
[ORDER_BY=NONE]

ACCT         ORDER_DATE        QUANT  TOTAL                             
-----------  ----------------  -----  --------------------------------  
          1      Feb 20, 1996     19                      31122.000000  
1 row returned
> ; <TEST=PRBQ2>
> ;147
> select count(*) from activity a, prospects p \
 (cont) >   where a.acct = p.acct and (p.company like '%Systems%')
[SELECT_ITEMS=
1,Expr,"COUNT('*')",,UNS INT(4),,C STRING(11)]
[ORDER_BY=NONE]

COUNT('*')  
----------  
        41  
1 row returned
> ; <TEST=PRBQ3>
> ;148
> select count(a.dt) from orders o, activity a \
 (cont) >   where o.acct = a.acct and \
 (cont) >   (a.dt between '07-31-1997' and '12-31-1997' \
 (cont) >    or o.order_date between '07-31-1997' and '12-31-1997')
[SELECT_ITEMS=
1,Expr,"COUNT(A.DT)",,UNS INT(4),,C STRING(11)]
[ORDER_BY=NONE]

COUNT(A.DT  
----------  
       236  
1 row returned
> ;
> ;   Double-check tidmap works (for oracle)
> ;
> ; <TEST=PRBQ4>
> ;149
> select yr, jan_total from orders_rollup where num_orders between 20 and 40
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.ORDERS_ROLLUP.YR,,ODX DATE(2),YYYY,C STRING(11)
2,Column,STAR_ENV.STAR.ORDERS_ROLLUP.JAN_TOTAL,,DOUBLE(8),,C STRING(33)]
[ORDER_BY=NONE]

YR          JAN_TOTAL                         
----------  --------------------------------  
      1990                        694.199996  
      1992                       6115.980012  
      1993                       3627.780060  
3 rows returned
> ; <TEST=PRBQ5>
> ;150
> select jan_total, retail, yr from orders_rollup where jan_total > 0
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.ORDERS_ROLLUP.JAN_TOTAL,,DOUBLE(8),,C STRING(33)
2,Column,STAR_ENV.STAR.ORDERS_ROLLUP.RETAIL,,DOUBLE(8),,C STRING(33)
3,Column,STAR_ENV.STAR.ORDERS_ROLLUP.YR,,ODX DATE(2),YYYY,C STRING(11)]
[ORDER_BY=NONE]

JAN_TOTAL                         RETAIL                            
--------------------------------  --------------------------------  
YR          
----------  
                      694.199996                      32754.539991  
      1990  
                    18050.760010                      27021.540234  
      1991  
                     6115.980012                      16404.180061  
      1992  
                     3627.780060                      25675.259678  
      1993  
                    30598.799988                      56999.520061  
      1994  
                     4952.580004                      49981.500072  
      1995  
6 rows returned
> ;
> ;   Check date aggs for y2k
> ;
> ; <TEST=PRBQ6>
> ;151
> select count(distinct dt) from dates group by mo
[SELECT_ITEMS=
1,Expr,"COUNT(DISTINCT DATES.DT)",,UNS INT(4),,C STRING(11)]
[ORDER_BY=NONE]

COUNT(DIST  
----------  
       372  
       339  
       372  
       360  
       372  
       360  
       372  
       372  
       360  
       372  
       360  
       372  
12 rows returned
> ; <TEST=PRBQ7>
> ;152
> select min(dt), max(dt) from dates \
 (cont) >   where yr between 1993 and 2003
[SELECT_ITEMS=
1,Expr,"MIN(DATES.DT)",,ODX DATE(4),YYYYMMDD,C STRING(17)
2,Expr,"MAX(DATES.DT)",,ODX DATE(4),YYYYMMDD,C STRING(17)]
[ORDER_BY=NONE]

MIN(DATES.DT)     MAX(DATES.DT)     
----------------  ----------------  
     Jan 1, 1993      Dec 31, 2001  
1 row returned
> ;
> ;   Check required_optimization, ask_retrieval_threshold
> ; <SECTION=REQ_OPT>
> ; <TEST=RO1>
> ;153
> select top 5 acct, quantity, total from orders order by 1,2,3 \
 (cont) >   with required = 'no_unoptimized_criteria \
 (cont) >    no_sequential_table_join no_xref_files \
 (cont) >    no_unoptimized_aggregation no_cartesian_products'
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.ORDERS.ACCT,,INT(4),,C STRING(12)
2,Column,STAR_ENV.STAR.ORDERS.QUANTITY,,TINYINT(1),,C STRING(6)
3,Column,STAR_ENV.STAR.ORDERS.TOTAL,,FLOAT(4),,C STRING(33)]
[ORDER_BY=1,2,3]

ACCT         QUANT  TOTAL                             
-----------  -----  --------------------------------  
          1      1                          0.780000  
          1      1                          0.780000  
          1      1                          0.780000  
          1      1                          0.780000  
          1      1                          1.560000  
5 rows returned
> ;
> ; <TEST=RO2>
> ;154  /* should fail except on nonopt */
> select O.ACCT, A.ACCT \
 (cont) >   from  ORDERS O, ACTIVITY A, PROSPECTS P, INITIALS I \
 (cont) >   where O.ACCT = P.ACCT and A.ACCT = P.ACCT and A.INITIALS = I.INITIALS and \
 (cont) >         O.ACCT = 3 and A.ACCT = 3 \
 (cont) >   with required='no_xref_files'
*E* Couldn't optimize according to REQUIRED_OPTIMIZATION settings: NO_XREF_FILES.
(10166 0 16 )
> ;
> ; <TEST=RO3>
> ;155
> select count(distinct total), count(distinct product_no), count(distinct quantity), \
 (cont) >   count(distinct order_date) from orders \
 (cont) >   where tax_state in ('CO', 'CA', 'AZ') and \
 (cont) >         (discount < 10 or (quantity > 15 and amount > 100)) \
 (cont) >   group by acct with ask_retrieval_threshold = 20
[SELECT_ITEMS=
1,Expr,"COUNT(DISTINCT ORDERS.TOTAL)",,UNS INT(4),,C STRING(11)
2,Expr,"COUNT(DISTINCT ORDERS.PRODUCT_NO)",,UNS INT(4),,C STRING(11)
3,Expr,"COUNT(DISTINCT ORDERS.QUANTITY)",,UNS INT(4),,C STRING(11)
4,Expr,"COUNT(DISTINCT ORDERS.ORDER_DATE)",,UNS INT(4),,C STRING(11)]
[ORDER_BY=NONE]

COUNT(DIST  COUNT(DIST  COUNT(DIST  COUNT(DIST  
----------  ----------  ----------  ----------  
        10           9           4          10  
1 row returned
> ;
> ;  'Kellogg' optimization:  all select items come from child; not all parents linked
> ; <SECTION=MULTIFIND>
> ;
> ;2 parents, neither linked
> ; <TEST=MF1>
> ;156
> select         sum(amount), sum(total), min(quantity) \
 (cont) >   from         pmt_methods pmt, \
 (cont) >                states sts, \
 (cont) >                orders ord \
 (cont) >   where        pmt.pmt_method = ord.pmt_method and \
 (cont) >                sts.state = ord.tax_state and \
 (cont) >                pmt.description in ('Cash', 'Check') and \
 (cont) >                sts.description = 'Texas'
[SELECT_ITEMS=
1,Expr,"SUM(ORD.AMOUNT)",,DOUBLE(8),,C STRING(33)
2,Expr,"SUM(ORD.TOTAL)",,DOUBLE(8),,C STRING(33)
3,Expr,"MIN(ORD.QUANTITY)",,TINYINT(1),,C STRING(6)]
[ORDER_BY=NONE]

SUM(ORD.AMOUNT)                   SUM(ORD.TOTAL)                    MIN(O  
--------------------------------  --------------------------------  -----  
                     2795.400000                      35195.400000      1  
1 row returned
> ;2 parents, one linked
> ; <TEST=MF2>
> ;157
> select         count(amount) \
 (cont) >   from         pmt_methods pmt, \
 (cont) >                products prd, \
 (cont) >                orders ord \
 (cont) >   where        pmt.pmt_method = ord.pmt_method and \
 (cont) >                ord.product_no = prd.product_no and \
 (cont) >                pmt.description in ('Cash', 'Check') and \
 (cont) >                prd.margin < 50.0 \
 (cont) >   group by     acct
[SELECT_ITEMS=
1,Expr,"COUNT(ORD.AMOUNT)",,UNS INT(4),,C STRING(11)]
[ORDER_BY=NONE]

COUNT(ORD.  
----------  
        28  
         5  
2 rows returned
> ;3 parents, 1 linked
> ; <TEST=MF3>
> ;158
> select         order_date, sum(amount), sum(total), min(quantity), count(*) \
 (cont) >   from         pmt_methods pmt, \
 (cont) >                states sts, \
 (cont) >                products prd, \
 (cont) >                orders ord \
 (cont) >   where        pmt.pmt_method = ord.pmt_method and \
 (cont) >                sts.state = ord.tax_state and \
 (cont) >                prd.product_no = ord.product_no and \
 (cont) >                pmt.description in ('Cash', 'Check') and \
 (cont) >                prd.category > 30 and \
 (cont) >                sts.description = 'Texas' \
 (cont) >   group by     ord.order_date
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.ORD.ORDER_DATE,,ODX DATE(4),YYYYMMDD,C STRING(17)
2,Expr,"SUM(ORD.AMOUNT)",,DOUBLE(8),,C STRING(33)
3,Expr,"SUM(ORD.TOTAL)",,DOUBLE(8),,C STRING(33)
4,Expr,"MIN(ORD.QUANTITY)",,TINYINT(1),,C STRING(6)
5,Expr,"COUNT('*')",,UNS INT(4),,C STRING(11)]
[ORDER_BY=NONE]

ORDER_DATE        SUM(ORD.AMOUNT)                   
----------------  --------------------------------  
SUM(ORD.TOTAL)                    MIN(O  COUNT('*')  
--------------------------------  -----  ----------  
    Mar 20, 1994                        180.900000  
                      180.900000      1           2  
    Sep 20, 1994                       2160.000000  
                    34560.000000     16           1  
    Nov 20, 1994                        180.000000  
                      180.000000      1           1  
    Jul 20, 1995                          4.500000  
                        4.500000      1           1  
4 rows returned
> ;4 parents, 2 linked, and qualify in child
> ; <TEST=MF4>
> ;159
> select         sum(amount), sum(total), min(quantity), count(*) \
 (cont) >   from         prospects prs, \
 (cont) >                pmt_methods pmt, \
 (cont) >                states sts, \
 (cont) >                products prd, \
 (cont) >                orders ord \
 (cont) >   where        prs.acct = ord.acct and \
 (cont) >                pmt.pmt_method = ord.pmt_method and \
 (cont) >                sts.state = ord.tax_state and \
 (cont) >                prd.product_no = ord.product_no and \
 (cont) >                prs.company like '%Systems%' and \
 (cont) >                pmt.description in ('Cash', 'Check') and \
 (cont) >                prd.category > 50 and \
 (cont) >                sts.description = 'Colorado' and \
 (cont) >                ord.quantity > 5
[SELECT_ITEMS=
1,Expr,"SUM(ORD.AMOUNT)",,DOUBLE(8),,C STRING(33)
2,Expr,"SUM(ORD.TOTAL)",,DOUBLE(8),,C STRING(33)
3,Expr,"MIN(ORD.QUANTITY)",,TINYINT(1),,C STRING(6)
4,Expr,"COUNT('*')",,UNS INT(4),,C STRING(11)]
[ORDER_BY=NONE]

SUM(ORD.AMOUNT)                   SUM(ORD.TOTAL)                    MIN(O  
--------------------------------  --------------------------------  -----  
COUNT('*')  
----------  
                      941.460016                       9215.700108      7  
         7  
1 row returned
> ;same as 156 but count(*) only
> ; <TEST=MF5>
> ;160
> select         count(*) \
 (cont) >   from         pmt_methods pmt, \
 (cont) >                states sts, \
 (cont) >                orders ord \
 (cont) >   where        pmt.pmt_method = ord.pmt_method and \
 (cont) >                sts.state = ord.tax_state and \
 (cont) >                pmt.description in ('Cash', 'Check') and \
 (cont) >                sts.description = 'Texas'
[SELECT_ITEMS=
1,Expr,"COUNT('*')",,UNS INT(4),,C STRING(11)]
[ORDER_BY=NONE]

COUNT('*')  
----------  
         6  
1 row returned
> ;
> ; long in-clauses turned into multifind
> ; <TEST=MF6>
> ;161
> select sum(total) from orders o, products p where o.product_no = p.product_no  \
 (cont) > and (category in (11,12,13,14,16,18,20,21,22,23,24,25,26,30,31,40,41,42,43,50,51,52,53,60,61,62,80,81,90,91,92,93,94,95) \
 (cont) > or   description in ( 'Desk', 'Chair', 'File', 'Phone', 'Credenza', 'Computer', 'Copier', 'Printer', 'Deskjet', 'Laserjet', 'Cellular', 'Cordless', 'Fax', 'Paper', 'Pens', 'Pencils', 'Markers', 'Erasers' ) ) \
 (cont) > and (order_date in ('01-20-1994','02-20-1994','03-20-1994','04-20-1994','05-20-1994','06-20-1994','07-20-1994','08-20-1994','09-20-1994','10-20-1994','11-20-1994','12-20-1994','01-20-1995','02-08-1995','02-20-1995','03-20-1995','04-20-1995','05-20-1995','06-20-1995','07-20-1995','08-20-1995','09-20-1995','10-20-1995','11-20-1995','12-20-1995','02-20-1996','04-20-1996','05-20-1996','06-23-1996','08-20-1996','09-20-1996','09-20-1993','10-20-1993','11-20-1993','12-20-1993','10-20-1996','02-14-2001') \
 (cont) > and quantity in (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59) \
 (cont) > and  acct in (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16) and (tax_state = 'CO' or tax_state = 'TX'))
[SELECT_ITEMS=
1,Expr,"SUM(O.TOTAL)",,DOUBLE(8),,C STRING(33)]
[ORDER_BY=NONE]

SUM(O.TOTAL)                      
--------------------------------  
                   360088.081333  
1 row returned
> ;
> ; <SECTION=PARTITIONED_QUALIFY>
> ; <TEST=PQ1>
> ;162
> ;Character, single column
> ; No group by
> select max(total) from orders where status in ('CN', 'OR', 'SH', 'BO')
[SELECT_ITEMS=
1,Expr,"MAX(ORDERS.TOTAL)",,FLOAT(4),,C STRING(33)]
[ORDER_BY=NONE]

MAX(ORDERS.TOTAL)                 
--------------------------------  
                    36190.441406  
1 row returned
> ;
> ; <TEST=PQ2>
> ;163
> ; Group by
> select product_no, min(total) from orders where product_no in ('P900', 'XPCP', 'S100', 'A940', 'G523') group by product_no
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.ORDERS.PRODUCT_NO,,CHAR(4),,CHAR(4)
2,Expr,"MIN(ORDERS.TOTAL)",,FLOAT(4),,C STRING(33)]
[ORDER_BY=NONE]

PROD  MIN(ORDERS.TOTAL)                 
----  --------------------------------  
A940                       1638.000000  
G523                       1829.880005  
P900                        132.600006  
S100                        156.000000  
XPCP                         22.620001  
5 rows returned
> ;
> ; <TEST=PQ3>
> select status, product_no, sum(amount) from orders \
 (cont) > where status in ('SH','CN') and \
 (cont) > product_no = 'A940' group by status, product_no
[SELECT_ITEMS=
1,Column,STAR_ENV.STAR.ORDERS.STATUS,,CHAR(2),,CHAR(2)
2,Column,STAR_ENV.STAR.ORDERS.PRODUCT_NO,,CHAR(4),,CHAR(4)
3,Expr,"SUM(ORDERS.AMOUNT)",,DOUBLE(8),,C STRING(33)]
[ORDER_BY=NONE]

ST  PROD  SUM(ORDERS.AMOUNT)                
--  ----  --------------------------------  
CN  A940                       1638.000000  
SH  A940                      12222.000000  
2 rows returned
> ;
> ;<COMMON>
> disconnect
Disconnected from instance 1
> 
> 
