如何将两列相加以在mysql中创建一个新列 [英] How to sum two columns to create a new column in mysql
本文介绍了如何将两列相加以在mysql中创建一个新列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
创建表格标记
(
MId int主键,
TheoryMarks浮动,
实用标记浮动
)
现在我需要添加一个名为ObtainedMarks的第四列作为TheoryMarks + PracticalMarks。
这适用于SqlServer。
怎么做?
我尝试过:
创建表格标记
(
MId int主键,
TheoryMarks浮动,
实用标记浮动,
TheoryMarks + PracticalMarks As ObtainedMarks
)
Create table marks
(
MId int primary key,
TheoryMarks float,
Practical Marks float
)
Now i need to add a fourth column named ObtainedMarks as TheoryMarks+PracticalMarks.
This works with SqlServer.
How to do this?
What I have tried:
Create table marks
(
MId int primary key,
TheoryMarks float,
Practical Marks float,
TheoryMarks+PracticalMarks As ObtainedMarks
)
推荐答案
使用生成的列 [ ^ ] - 它允许您要创建一个作为表达式的列,并在存储行或calc时自动设置该值当你阅读它时,请立即进行操作。
Use a Generated Column[^] - it allows you to create a column which is an expression and either automatically set the value when the row is stored, or calculate it on the fly when you read it.
这篇关于如何将两列相加以在mysql中创建一个新列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文