是否可以在 mysql 中创建一个包含两个列值的列的表?像这样:
create table test1 (
number1 int,
number2 int,
total int DEFAULT (number1+number2)
);
或者像这样:
CREATE TABLE `Result` (
`aCount` INT DEFAULT 0,
`bCount` INT DEFAULT 0,
`cCount` = `aCount` + `bCount`
);
最佳答案
不可能完全做到这一点,但您可以基于组合它们的查询创建 View :
CREATE VIEW `my_wacky_view` AS
SELECT `number1`, `number2`, `number1` + `number2` AS `total`
FROM `test1`;
我会避免将组合数据实际存储在表中,除非您要运行大量查询,这些查询将在 WHERE 子句中引用组合数据。
关于mysql - 在 mysql 中创建表,其中一列包含另外两列值的总和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6805498/