Hi! Could we please enable some services and cookies to improve your experience and our website?

SQLize | PHPize | SQLtest

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

A A A
Login    Share code      Blog   FAQ
Copy Format Clear
-- basicly we need one table for store price changes history CREATE TABLE price_history ( id serial, price_date timestamp, price numeric ); -- for ability to store separated prices for different products -- we need to create table products CREATE TABLE products ( id serial primary key, name varchar ); -- and add column product_id into price_history ALTER TABLE price_history ADD product_id int REFERENCES products(id); -- add index for select performance CREATE INDEX price_history_product_id_ix ON price_history(product_id); -- because same product can have differen price at different suppliers -- we do next iteration CREATE TABLE suppliers ( id serial primary key, name varchar ); ALTER TABLE price_history ADD supplier_id int REFERENCES suppliers(id); CREATE INDEX price_history_supplier_id_ix ON price_history(supplier_id); -- same way we will add all parameters as city, devivery, and so on

Stuck with a problem? Got Error? Ask AI support!

Copy Clear