Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE TABLE customer (
- name VARCHAR(20) NOT NULL,
- surname VARCHAR(40) NOT NULL,
- passport_numer CHAR(10),
- id_customer serial PRIMARY KEY
- );
- CREATE TABLE genre(
- genre_name VARCHAR(30) NOT NULL,
- id_genre serial PRIMARY KEY
- );
- CREATE TABLE disc(
- title VARCHAR(40) NOT NULL,
- num serial PRIMARY KEY,
- price NUMERIC(4,2),
- genre INTEGER REFERENCES genre ON DELETE SET NULL ON
- UPDATE CASCADE
- );
- CREATE TABLE rent(
- who_rent INT NOT NULL REFERENCES customer ON DELETE RESTRICT ON UPDATE RESTRICT,
- what_rent INT NOT NULL REFERENCES disc ON DELETE RESTRICT ON UPDATE CASCADE,
- rent_date TIMESTAMP DEFAULT now(),
- back_date TIMESTAMP,
- PRIMARY KEY(who_rent, what_rent,rent_date)
- );
- SELECT
- rented_disc.title AS rented_disc_title,
- rented_disc.num AS rented_disc_num,
- rented_disc.price AS rented_disc_price,
- disc.title AS price_matched_disc_title
- disc.num AS price_matched_disc_num
- FROM
- rent
- INNER JOIN disc AS rented_disc ON
- rent.what_rent = rented_disc.num
- INNER JOIN disc
- rented_disc.price = disc.price
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement