SQL Server 中的两列相乘
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7536996/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Multiplying Two Columns in SQL Server
提问by Vonn Liquiran
How can I perform operations such as Multiplying and Subtracting two columns in SQL Server?
如何在 SQL Server 中执行诸如两列相乘和相减之类的操作?
Payment
PK - PaymentID
FK - PaymentTypeID
FK - OccupiedApartmentID
**- InitalPayment
- MonthlyRate
- Balance**
- PaymentDate
回答by Nigel Whatling
In a query you can just do something like:
在查询中,您可以执行以下操作:
SELECT ColumnA * ColumnB FROM table
or
或者
SELECT ColumnA - ColumnB FROM table
You can also create computed columns in your table where you can permanently use your formula.
您还可以在表中创建计算列,您可以在其中永久使用您的公式。
回答by Al W
select InitialPayment * MonthlyPayRate as SomeRandomCalculation from Payment
回答by Mr.DIpak SOnar
Syntax:
句法:
SELECT <Expression>[Arithmetic_Operator]<expression>...
FROM [Table_Name]
WHERE [expression];
- Expression: Expression made up of a single constant, variable, scalar function, or column name and can also be the pieces of a SQL query that compare values against other values or perform arithmetic calculations.
- Arithmetic_Operator: Plus(+), minus(-), multiply(*), and divide(/).
- Table_Name: Name of the table.
- 表达式:由单个常量、变量、标量函数或列名组成的表达式,也可以是将值与其他值进行比较或执行算术计算的 SQL 查询片段。
- Arithmetic_Operator:加(+)、减(-)、乘(*)和除(/)。
- Table_Name:表的名称。
回答by hadi safari
This code is used to multiply the values of one column
此代码用于乘以一列的值
select exp(sum(log(column))) from table