开发者

Multiplying Two Columns in SQL Server

How can I perform operations such as Multiplying and Subtracting two columns in SQL Server?

Payment
PK - PaymentID
FK - PaymentTypeID
FK - OccupiedApartmentID
 开发者_StackOverflow中文版  **- InitalPayment
   - MonthlyRate
   - Balance**
   - PaymentDate


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.


select InitialPayment * MonthlyPayRate as SomeRandomCalculation from Payment


Syntax:

SELECT <Expression>[Arithmetic_Operator]<expression>...
 FROM [Table_Name] 
 WHERE [expression];
  1. 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.
  2. Arithmetic_Operator : Plus(+), minus(-), multiply(*), and divide(/).
  3. Table_Name : Name of the table.


This code is used to multiply the values of one column

select exp(sum(log(column))) from table


You can use the query:

for multiplication

Select columnA * cloumnB as MultiplyResult from TableName

for subtraction

Select columnA - cloumnB as SubtractionResult from TableName


select InitialPayment * MonthlyRate as MultiplyingCalculation,
InitialPayment - MonthlyRate as SubtractingCalculation
 from Payment
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜