Q: Calculated columns?
Is it possible to have calculated fields? e.g. Add values from Column 1 and Column 2 and put calculated value in Column 3.
jass_
Jan 19, 2025A: Hi,
Yes its completely possible. We have an advanced feature where a user can write custom SQL queries to generate complex relations. You can use this for the same.
Suppose you have an orders table with price and quantity columns, and you want to create a column total_cost that calculates price * quantity. You can write below SQL query to create a column to store the calculation:
CREATE TABLE orders (
price DECIMAL(10,2),
quantity INT,
total_cost DECIMAL(10,2) AS (price * quantity) STORED
);
Here:
total_cost is a generated column and will store the calculated value (price * quantity) in the table.