CREATE TABLE sales (
customer_id NUMBER,
product_id NUMBER,
order_date DATE NOT NULL,
total NUMBER(9, 2) DEFAULT 0 NOT NULL,
PRIMARY KEY(
customer_id,
product_id,
order_date
)
);
INSERT INTO
sales(customer_id, product_id, order_date, total)
VALUES
(1, 2, CURRENT_DATE, 10);
INSERT INTO
sales(customer_id, product_id, order_date, total)
VALUES
(2, 2, DATE '2017-05-01', 9);
CREATE TABLE discounts (
discount_id NUMBER GENERATED BY DEFAULT AS IDENTITY,
discount_name VARCHAR2(255) NOT NULL,
amount NUMBER(3, 1) NOT NULL,
start_date DATE NOT NULL,
expired_date DATE NOT NULL
);
INSERT INTO
discounts(discount_name, amount, start_date, expired_date)
VALUES
(
'Summer Promotion',
9.5,
DATE '2017-05-01',
DATE '2017-08-31'
);
INSERT INTO
discounts(discount_name, amount, start_date, expired_date)
VALUES
(
'Winter Promotion 2017',
10.5,
CURRENT_DATE,
DATE '2017-12-31'
);
ALTER TABLE
sales RENAME COLUMN total TO amount;
update
discounts
set
amount = 10
where
discount_name = 'Summer Promotion';
select * from sales;
select * from discounts;
select
discount_name
from
discounts
where
amount not in (
select
amount
from
sales
where
customer_id = 1
);