sql - 我可以为 SQL 中的特定列设置公式吗?

标签 sql

我想在 SQL 中实现类似 Col3 = Col2 + Col1 的东西。

这有点类似于 Excel,其中第 3 列中的每个值都是第 2 列和第 1 列中相应值的总和。

最佳答案

看看Computed Columns

A computed column is computed from an expression that can use other columns in the same table. The expression can be a noncomputed column name, constant, function, and any combination of these connected by one or more operators.



同样来自 CREATE TABLE J点

就像是
CREATE TABLE dbo.mytable 
( low int, high int, myavg AS (low + high)/2 ) ;

关于sql - 我可以为 SQL 中的特定列设置公式吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2415398/

相关文章:

java - 如何根据用户点击检索数据库值

sql - 计算在行类型 2 日期之间找到行类型 1 的次数

php - 带有 SQL 函数的 Doctrine DQL 查询

sql - T-SQL正则表达式替换

php - Mysql限制

mysql - 如何使这个 MySql 查询适应 PervasiveSql?

java - 如何使用某些与 SQL 兼容的列类型在 Spring JPA 中存储 Joda 时间(任何)?

javascript - PHP 值重复两次

sql - 在 PostgreSQL 表中使用模式名称作为外键

java - 在 Java 中解析 SQL 查询