I have 3 sql tables: In first I store products with key PID. In second I save invoices with key RID. Third table is used to describe how many of each product is bought in this invoice. I need a help with the two issues, and as someone who rarely worked with sql, this is somewhat hard.
1) What would be the query for the most bought products in the last 3 months.
2) What would be the query to increase the price of these 3 products by 5%?
DB:
CREATE TABLE Products(
pid INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
name VARCHAR(30) NOT NULL,
type VARCHAR(8) NOT NULL,
price DOUBLE NOT NULL,
stock INTEGER NOT NULL);
CREATE TABLE Invoices(
rid INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
invoicedate TIMESTAMP NOT NULL);
CREATE TABLE Orders(
rid INTEGER,
pid INTEGER,
quantity INTEGER NOT NULL,
FOREIGN KEY (pid) REFERENCES Products(pid) ON DELETE CASCADE,
FOREIGN KEY (rid) REFERENCES Invoices(rid) ON DELETE CASCADE);
for increasing price