MySQL 5.7 supports Generated Columns and 5.6 doesn't.
Generated Columns. MySQL now supports the specification of generated columns in CREATE TABLE and ALTER TABLE statements. Values of a generated column are computed from an expression specified at column creation time. Generated columns can be virtual (computed “on the fly” when rows are read) or stored (computed when rows are inserted or updated). For more information, see Section 13.1.18.7, “CREATE TABLE and Generated Columns”.
All you need to do is to follow the documentation.
This is a really simple table to match what's in your question on MySQL 5.7.36.
CREATE TABLE `Product` (
`id` int(11) DEFAULT NULL,
`amount` int(11) DEFAULT NULL,
`sold_out` int(11) DEFAULT NULL,
`faulty` int(11) DEFAULT NULL,
`remain_amount` int(11) GENERATED ALWAYS AS ((`amount` - (`sold_out` + `faulty`))) VIRTUAL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
INSERT Product VALUES(1, 10, 4, 1, DEFAULT);
INSERT Product (id, amount, sold_out, faulty) VALUES (2, 5, 4, 1);
SELECT * FROM Product;
+------+--------+----------+--------+---------------+
| id | amount | sold_out | faulty | remain_amount |
+------+--------+----------+--------+---------------+
| 1 | 10 | 4 | 1 | 5 |
| 2 | 5 | 4 | 1 | 0 |
+------+--------+----------+--------+---------------+
2 rows in set (0.00 sec)
Note that MySQL 5.7 supports 2 types of Generated Columns depending on your use case:
VIRTUAL, values are not stored, it is evaluated on reads.
STORED, values are stored on writes (inserts and updates).
The default is VIRTUAL if neither keyword is specified.
2nd Note, DEFAULT is the only permitted value for the Generated Columns, or you have to exclude the generated column.
That's why the insert statements are like this in the above example
INSERT Product VALUES(1, 10, 4, 1, DEFAULT);
# or
INSERT Product (id, amount, sold_out, faulty) VALUES (2, 5, 4, 1);
Read more about the details here