SQL>
SQL> CREATE TABLE price_avg
2 (product VARCHAR(20)
3 ,whn DATE
4 ,price DECIMAL(10,2)
5 ,PRIMARY KEY (product,whn)
6 );
Table created.
SQL> INSERT INTO price_avg VALUES ('Product A',DATE '2006-05-19', 10);
1 row created.
SQL> INSERT INTO price_avg VALUES ('Product A',DATE '2006-05-20', 10);
1 row created.
SQL> INSERT INTO price_avg VALUES ('Product A',DATE '2006-05-21', 10.5);
1 row created.
SQL> INSERT INTO price_avg VALUES ('Product A',DATE '2006-05-22', 10.5);
1 row created.
SQL>
SQL>
SQL> CREATE TABLE price_delta
2 (product VARCHAR(20)
3 ,whn DATE
4 ,price DECIMAL(10,2)
5 ,PRIMARY KEY (product,whn)
6 );
Table created.
SQL>
SQL> INSERT INTO price_delta VALUES ('Product A',DATE '2001-01-01', 10);
1 row created.
SQL> INSERT INTO price_delta VALUES ('Product A',DATE '2006-05-21', 10.5);
1 row created.
SQL> INSERT INTO price_delta VALUES ('Product A',DATE '2005-06-15', 9);
1 row created.
SQL> INSERT INTO price_delta VALUES ('Product B',DATE '2001-01-01', 12);
1 row created.
SQL> INSERT INTO price_delta VALUES ('Product B',DATE '2005-06-15', 13);
1 row created.
SQL>
SQL> SELECT price
2 FROM price_avg
3 WHERE product='Product A' AND whn=DATE '2006-05-20';
PRICE
----------
10
SQL>
SQL> DROP TABLE price_avg;
Table dropped.
SQL> DROP TABLE price_delta;
Table dropped.