I'm currently working on a simple dummy project to refresh my knowledge on SQL and to learn a few new things :)
I have a table Article
with the columns:
aID, price
I have another table Storage
:
sID, aID, count
The Storage
table references the aID
as a foreign key and the count column say how much of an article is stored.
Now I want to add a column value
to my Storage
table. This column should be calculated by Article.price * Storage.count
.
I found after searching the web that you can have calculated columns like this
CREATE TABLE tbl
(
int1 INT,
int2 INT,
product BIGINT GENERATED ALWAYS AS (int1 * int2) STORED
);
But I haven't found an example how to this with columns from another table.
What do I have to do in order to use the price from the referenced aID in the calculation?